Pat1029代碼
舊鍵盤上壞了幾個鍵,於是在敲一段文字的時候,對應的字符就不會出現。現在給出應該輸入的一段文字、以及實際被輸入的文字,請你列出肯定壞掉的那些鍵。
輸入格式:
輸入在2行中分別給出應該輸入的文字、以及實際被輸入的文字。每段文字是不超過80個字符的串,由字母A-Z(包括大、小寫)、數字0-9、以及下劃線“_”(代表空格)組成。題目保證2個字符串均非空。
輸出格式:
按照發現順序,在一行中輸出壞掉的鍵。其中英文字母只輸出大寫,每個壞鍵只輸出一次。題目保證至少有1個壞鍵。
輸入樣例:
7_This_is_a_test
_hs_s_a_es
輸出樣例:
7TI
代碼:#include<cstdio>
#include<cstdlib>
#include<map>
#define MAXN 100
using namespace std;
void featureNormalize(char str[]){
for(int i=0;str[i]!='\0';i++){
if(str[i]>='a'&&str[i]<='z'){
str[i]=str[i]-'a'+'A';
}
}
}
int main(int argc,char *argv[]){
char stdInput[MAXN];
char factInput[MAXN];
map<char,int> m;
scanf("%s",stdInput);
scanf("%s",factInput);
featureNormalize(stdInput);
featureNormalize(factInput);
for(int i=0;factInput[i]!='\0';i++){
char key=factInput[i];
m[key]++;
}
for(int i=0;stdInput[i]!='\0';i++){
char key=stdInput[i];
if(m[key]==0){
printf("%c",key);
m[key]++;
}
}
printf("\n");
}