题目描述
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 FORMAT
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.
翻译:每个输入文件包含一组测试数据。对于每组输入数据,第一行包括起始字符串,第二行为实际打出的字符串。每个字符串不超过80个字符,仅包括英文字母 [A-Z] (大小写不敏感),数字[0-9],或“_”(代替空格)。保证所有字符串不为空。
OUTPUT FORMAT
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
解题思路
通过Hash计算出原字符串减去匹配字符串后的各字符数量,如果大于0则输出。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#define INF 99999999
using namespace std;
int Hash[256];
int main(){
string s,p;
cin>>s;
cin>>p;
for(int i=0;i<s.size();i++){
if(s[i]>='a'&&s[i]<='z')s[i]=s[i]-'a'+'A';
Hash[s[i]]++;
}
for(int i=0;i<p.size();i++){
if(p[i]>='a'&&p[i]<='z')p[i]=p[i]-'a'+'A';
Hash[p[i]]--;
}
for(int i=0;i<s.size();i++){
if(Hash[s[i]]>0){
printf("%c",s[i]);
Hash[s[i]]=0;
}
}
printf("\n");
return 0;
}