pat 乙级 1033 旧键盘打字

一定要注意strlen函数的正确使用 在已经明确定义char大小时,strlen将给出已定大小,而不是截止到'\0'
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <ctype.h>
 6 
 7 int main()
 8 {
 9     char bad[42];
10     char ch[100001];
11     gets(bad);
12     gets(ch);
13     int flag = 1;
14     int flag2 = 1;
15     for (int i = 0; i < strlen(bad); ++i)
16     {
17         if (bad[i] == '+')
18         {
19             flag2 = 0;
20             break;
21         }
22     }
23     for (int i = 0; ch[i]!='\0'; ++i)
24     {
25         flag = 1;
26         for (int j = 0; bad[j]!='\0'; ++j)
27         {
28             if (bad[j] == ch[i] || bad[j] == toupper(ch[i]) || toupper(bad[j]) == ch[i])
29             {
30                 flag = 0;
31                 break;
32             }
33         }
34         if (flag == 1)
35         {
36             if (flag2 == 0)
37             {
38                 if (ch[i] >= 'A' && ch[i] <= 'Z')
39                     continue;
40             }
41             printf("%c", ch[i]);
42         }
43     }
44 
45     return 0;
46 }

 

posted @ 2023-03-20 14:24  雨中白发人  阅读(18)  评论(0)    收藏  举报