PAT 1084. Broken Keyboard (20)

http://www.patest.cn/contests/pat-a-practise/1084

 1 #include<cstdio>
 2 
 3 using namespace std;
 4 
 5 int hash[256];
 6 char s1[100];
 7 char s2[100];
 8 
 9 void to_upper(char *s) {
10     while(*s) {
11         if(*s >= 'a' && *s <= 'z') {
12             *s = *s - 'a' + 'A';
13         }
14         ++s;
15     }
16 }
17 
18 int main() {
19     scanf("%s%s", s1, s2);
20     to_upper(s1);
21     to_upper(s2);
22     char *ss1 = s1;
23     char *ss2 = s2;
24     while(*ss1 && *ss2) {
25         if(*ss1 == *ss2) {
26             ++ss1, ++ss2;
27         } else {
28             if(!hash[*ss1]) {
29                 putchar(*ss1);
30             }
31             hash[*ss1] = 1;
32             ++ss1;
33         }
34     }
35     while(*ss1) {
36         if(!hash[*ss1]) {
37             putchar(*ss1);
38         }
39         ++ss1;
40     }
41     putchar('\n');
42     return 0;
43 }

 

posted @ 2015-08-03 17:39  ACSeed  Views(139)  Comments(0)    收藏  举报