题解 | #Captcha Cracker#
Captcha Cracker
https://ac.nowcoder.com/acm/problem/13814
判断输入的字符串内的指定字符串
用string里的函数substr()提取字符串
#include <iostream> #include <string> using namespace std; int main(){ int n; cin >>n; while(n--){ string s; cin>>s; for(int i = 0;s[i];i++){ if(s[i]=='0'||s[i]=='2'||s[i]=='4'||s[i]=='6'||s[i]=='9'){ cout<<s[i]; } else if(s.substr(i,4)=="zero"){ cout<<'0'; i+=3; } else if(s.substr(i,3)=="two"){ cout<<'2'; i+=2; } else if(s.substr(i,4)=="four"){ cout<<'4'; i+=3; } else if(s.substr(i,3)=="six"){ cout<<'6'; i+=2; } else if(s.substr(i,4)=="nine"){ cout<<'9'; i+=3; } } cout<<endl; } return 0; }