【題目連接】spa
舊鍵盤上壞了幾個鍵,因而在敲一段文字的時候,對應的字符就不會出現。如今給出應該輸入的一段文字、以及實際被輸入的文字,請你列出確定壞掉的那些鍵。code
輸入格式:blog
輸入在2行中分別給出應該輸入的文字、以及實際被輸入的文字。每段文字是不超過80個字符的串,由字母A-Z(包括大、小寫)、數字0-九、以及下劃線「_」(表明空格)組成。題目保證2個字符串均非空。字符串
輸出格式:get
按照發現順序,在一行中輸出壞掉的鍵。其中英文字母只輸出大寫,每一個壞鍵只輸出一次。題目保證至少有1個壞鍵。string
輸入樣例:io
7_This_is_a_test _hs_s_a_es
輸出樣例:table
7TI
【提交代碼】class
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(void) 5 { 6 int i; 7 int table[10+26+1]; 8 9 char pStr1[100]; 10 char pStr2[100]; 11 char ch; 12 int len1, len2; 13 14 scanf("%s", pStr1); 15 scanf("%s", pStr2); 16 17 len1 = strlen(pStr1); 18 len2 = strlen(pStr2); 19 20 memset(table, 0x00, sizeof(table)); 21 // 記錄「實際被輸入的文字」的鍵,即沒有壞的鍵 22 for(i = 1; i <= len2; i++) 23 { 24 ch = pStr2[i-1]; 25 if(ch >= '0' && ch <= '9' && table[ch-'0'] == 0) 26 { 27 table[ch-'0'] = 1; 28 } 29 else if(ch >= 'a' && ch <= 'z' && table[ch-'a'+10] == 0) 30 { 31 table[ch-'a'+10] = 1; 32 } 33 else if(ch >= 'A' && ch <= 'Z' && table[ch-'A'+10] == 0) 34 { 35 table[ch-'A'+10] = 1; 36 } 37 else if(ch == '_' && table[10+26] == 0) 38 { 39 table[10+26] = 1; 40 } 41 } 42 // 從「應該輸入的文字」中檢測是否爲「實際被輸入的文字」 43 // 若是不是「實際被輸入的文字」則說明該鍵是壞掉的 44 for(i = 1; i <= len1; i++) 45 { 46 ch = pStr1[i-1]; 47 if(ch >= '0' && ch <= '9') 48 { 49 if(table[ch-'0'] == 0) 50 { 51 printf("%c", ch); 52 table[ch-'0'] = 1; 53 } 54 } 55 else if(ch >= 'a' && ch <= 'z') 56 { 57 if(table[ch-'a'+10] == 0) 58 { 59 printf("%c", ch-'a'+'A'); 60 table[ch-'a'+10] = 1; 61 } 62 } 63 else if(ch >= 'A' && ch <= 'Z') 64 { 65 if(table[ch-'A'+10] == 0) 66 { 67 printf("%c", ch); 68 table[ch-'A'+10] = 1; 69 } 70 } 71 else if(ch == '_') 72 { 73 if(table[10+26] == 0) 74 { 75 printf("%c", ch); 76 table[10+26] = 1; 77 } 78 } 79 } 80 81 return 0; 82 }