On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.
Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.
Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive), digital numbers [0-9], or?_ ?(representing the space). It is guaranteed that both strings are non-empty.
Output Specification:
For each test case, print in one line the keys that are worn out, in the order of being detected. The English letters must be capitalized. Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.
7_This_is_a_test
_hs_s_a_es
Sample Output:
7TI
代码如下:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str1, str2;
bool HashTable[128] = { false };//字符是否已经被输出
cin >> str1;
cin >> str2;
int len1 = str1.length();
int len2 = str2.length();
for (int i = 0; i < len1; i++)
{
int j;
char c1, c2;
for (j = 0; j < len2; j++)
{
c1 = str1[i];
c2 = str2[j];
if (c1 >= 'a' && c1 <= 'z')c1 -= 32;//小写转大写
if (c2 >= 'a' && c2 <= 'z')c2 -= 32;
if (c1 == c2)break;//共有字符
}
if (j == len2 && HashTable[c1] == false)//第二个字符中没有(正常结束循环,而不是break)
{
cout << c1;
HashTable[c1] = true;//已输出
}
}
return 0;
}
运行结果如下:
|