牛客网PAT练兵场-旧键盘打字

题目地址:https://www.nowcoder.com/pat/6/problem/4059

题解:用数组下标标记,直接模拟

 1 /**
 2 *
 3 *作者:Ycute
 4 *时间:2019-12-01-21.33.21
 5 *题目题意简单描述:用数组下标标记,直接模拟
 6 */
 7 
 8 
 9 #include<iostream>
10 #include<cmath>
11 #include<cstring>
12 #include<algorithm>
13 #include<vector>
14 using namespace std;
15 int main(){
16     bool flag[350]={0};
17     char temp[100005];
18     scanf("%s",temp);
19     for(int i=0;i<strlen(temp);i++){
20         if((temp[i]>='A'&&temp[i]<='Z')||(temp[i]>='a'&&temp[i]<='z')){
21             if(temp[i]>='A'&&temp[i]<='Z'){
22                 flag[temp[i]]=1;
23                 flag[temp[i]+32]=1;
24             }else{
25                 flag[temp[i]]=1;
26                 flag[temp[i]-32]=1;
27             }
28         }else{
29             flag[temp[i]]=1;
30         }
31     }
32     getchar();
33     scanf("%s",temp);
34     for(int i=0;i<strlen(temp);i++){
35         if((temp[i]>='A'&&temp[i]<='Z')||(temp[i]>='a'&&temp[i]<='z')){
36              if(temp[i]>='A'&&temp[i]<='Z'){
37                 if(!flag[temp[i]]){
38                     if(!flag['+']){
39                         printf("%c",temp[i]);
40                     }
41                 }
42             }else{
43                 if(!flag[temp[i]]){
44                 printf("%c",temp[i]);
45                 }
46              }
47         }else{
48             if(!flag[temp[i]]){
49                 printf("%c",temp[i]);
50             }
51         }
52     }
53 return 0;
54 }

猜你喜欢

转载自www.cnblogs.com/cutelife/p/11968237.html
今日推荐