乙级(Basic Level) 1019 旧键盘

题目描述

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出

肯定坏掉的那些键。

输入描述:

输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、

以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。

输出描述:

按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。

输入例子:

7_This_is_a_test

_hs_s_a_es

输出例子:

7TI

Python:
a1 = input()
a2 = input()
lst = ''
#lst = []
#lst2 = []
j = 0
for i in a1:
    if i != a2[j]:
        lst += i
        #lst.append(i)
    else:
        j += 1
        if j >= len(a2):
            j -= 1
lst = lst.upper()
lst2 = set(lst)
for i in lst:
    if i in lst2:
        print(i,end='')
        lst2.remove(i)
"""
for i in lst:
    if i.upper() not in lst2:
        lst2.append(i.upper())
        print(i.upper(),end='')
"""

 

OR:
res = ''
# c = '7_This_is_a_test'
# d = '_hs_s_a_es'
c = input()
d = input()
for i in c:
    if i not in d:
        if i.upper() not in res:
            res+=i.upper()
print (res)

 

C++:
#include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ int i,j,k; string a,b,c=""; cin>>a>>b; transform(a.begin(),a.end(),a.begin(),::toupper); transform(b.begin(),b.end(),b.begin(),::toupper); for(i=0,j=0;i<a.size();i++){ if (a[i]!=b[j]){ for(k=0;k<c.size();k++){ if(a[i] == c[k]){ k = -1; break; } } if(k!=-1) c += a[i]; } else{ j++; if(j>=b.size()) j--; } } cout<<c<<endl; return 0; }

 

posted @ 2018-08-23 12:57  黄冠积  阅读(104)  评论(0编辑  收藏  举报