1029. Old keyboard(20)
Several keys were broken on the old keyboard, so when typing a piece of text, the corresponding character would not appear. Now given a piece of text that should be typed, and the type of text that was actually typed, please list the keys that are definitely broken.
Input format:
The input gives the text that should be input and the text that is actually input in 2 lines, respectively. Each paragraph of text is a string of no more than 80 characters, consisting of letters AZ (including uppercase and lowercase), numbers 0-9, and underscore "_" (representing a space). The question ensures that both strings are not empty.
Output format:
Print the broken keys in one line, in the order they were found. Among them, English letters are only output in uppercase, and each bad key is output only once. The title is guaranteed to have at least 1 bad key.
Input sample:7_This_is_a_test _hs_s_a_esSample output:
7TI
Idea: 0-9, AZ, _ has the smallest ascll code value among the three, so use a vis to record it directly
#include<cstdio> #include<cstring> using namespace std; int main(){ //freopen("input.txt", "r", stdin); char arr1[100], arr2[100], ans[100]; int vis [100], len = 0; memset(vis, 0, sizeof(vis)); gets(arr1); gets(arr2); int i, j; for(i = 0, j = 0; i < strlen(arr1) && j < strlen(arr2); ){ if(arr1[i] == arr2[j]){ i++, j++; }else{ if(arr1[i] >= 'a' && arr1[i] <= 'z') arr1[i] -= 32; //This is directly converted to uppercase if(!vis[arr1[i]-'0']) { //Judgment vis [arr1 [i] - '0'] = 1; ans [len ++] = arr1 [i]; } i++; } } while(i < strlen(arr1)){ //If the given string has no output at the end and the above is not finished if(arr1[i] >= 'a' && arr1[i] <= 'z') arr1[i] -= 32; if(!vis[arr1[i]-'0']) { vis [arr1 [i] - '0'] = 1; ans [len ++] = arr1 [i]; } i++; } for(int i = 0; i < len; i++) printf("%c", ans[i]); return 0; }