北京师范大学校赛C
https://www.nowcoder.com/acm/contest/submit/0dff89ad7b8444719df155d507f3e1dd?ACMContestId=3&tagId=4
解析 字符比较 水
AC代码
1 #include <stdio.h> 2 #include <math.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <sstream> 7 #include <algorithm> 8 #include <string> 9 #include <queue> 10 #include <vector> 11 using namespace std; 12 const int maxn= 100005; 13 const int inf = 0x3f3f3f3f; 14 typedef long long ll; 15 char a[5][10]={"zero","two","four","six","nine"}; 16 char b[5]={'0','2','4','6','9'}; 17 char s[maxn]; 18 char k[maxn]; 19 int main(int argc, char const *argv[]) 20 { 21 int t; 22 cin>>t; 23 while(t--) 24 { 25 scanf("%s",s); 26 int len=strlen(s); 27 int t=0; 28 for(int i=0;i<len;) 29 { 30 if(s[i]=='0'||s[i]=='2'||s[i]=='4'||s[i]=='6'||s[i]=='9') 31 { 32 k[t++]=s[i]; 33 i++; 34 } 35 else if(s[i]=='1'||s[i]=='3'||s[i]=='5'||s[i]=='7'||s[i]=='8') 36 i++; 37 else 38 { 39 int flag1=0; 40 for(int j=0;j<5;j++) 41 { 42 int flag2=0,n=i; 43 int lenj=strlen(a[j]); 44 for(int l=0;l<lenj;l++) 45 { 46 if(s[n]==a[j][l]) 47 { 48 n++; 49 flag2++; 50 } 51 else 52 break; 53 } 54 if(flag2==lenj) 55 { 56 k[t++]=b[j]; 57 flag1=1; 58 i=n; 59 break; 60 } 61 } 62 if(flag1==0) 63 i++; 64 } 65 } 66 for(int i=0;i<t;i++) 67 cout<<k[i]; 68 cout<<endl; 69 } 70 }