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.
Input Specification:
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.
Sample Input:
7_This_is_a_test
_hs_s_a_es
Sample Output:
7TI
参考代码:
#include<cstdio>
#include<cstring>
bool hashTable[128] = {false};//用来标记字符是否已被输出
const int maxn = 100;
char str1[maxn], str2[maxn];
int main(int argc, char const *argv[])
{
fgets(str1, maxn + 1, stdin);
fgets(str2, maxn + 1, stdin);
int len1 = strlen(str1) - 1;//获取长度
int len2 = strlen(str2) - 1;
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){//第二个字符串中未出现c1,且c1位被输出过
printf("%c", c1);
hashTable[c1] = true;
}
}
printf("\n");
return 0;
}