枚举和暴力|L1-064 估值一亿的AI核心代码(模拟,string容器)

L1-064 估值一亿的AI核心代码 (20 分)
ac代码:

#include #define f(i,a,b) for(int i=a; i='A'&&s[i]<='Z'&&s[i]!='I') s[i]+=32; }for(int pos=0; ; pos++){ pos=s.find("can you",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+7==s.size() || !isalnum(s[pos+7]))){ s.replace(pos,7,"A can"); } } for(int pos=0; ; pos++){ pos=s.find("could you",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+9==s.size() || !isalnum(s[pos+9]))){ s.replace(pos,9,"A could"); } } for(int pos=0; ; pos++){ pos=s.find("I",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+1==s.size() || !isalnum(s[pos+1]))){ s.replace(pos,1,"you"); } } for(int pos=0; ; pos++){ pos=s.find("me",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+2==s.size() || !isalnum(s[pos+2]))){ s.replace(pos,2,"you"); } }f(i,0,s.size()){ if(s[i]=='?')s[i]='!'; else if(s[i]=='A')s[i]='I'; } return s; } int main(){ cin>>n; getchar(); string s; f(line,0,n){ getline(cin,s); cout<<

【枚举和暴力|L1-064 估值一亿的AI核心代码(模拟,string容器)】ac代码(标记坑点):
#include #define f(i,a,b) for(int i=a; i='A'&&s[i]<='Z'&&s[i]!='I') //错误示范: //s[i]-=26; s[i]+=32; }//错误示范(会超时): //for(int pos=0; ; ){ for(int pos=0; ; pos++){ pos=s.find("can you",pos); if(pos==-1) break; //错误示范: //if((!pos || !isalnum(s[pos-1])) && (pos+7!=s.size() || !isalnum(s[pos+7]))) if((!pos || !isalnum(s[pos-1])) && (pos+7==s.size() || !isalnum(s[pos+7]))){ s.replace(pos,7,"A can"); } } for(int pos=0; ; pos++){ pos=s.find("could you",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+9==s.size() || !isalnum(s[pos+9]))){ s.replace(pos,9,"A could"); } } for(int pos=0; ; pos++){ pos=s.find("I",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+1==s.size() || !isalnum(s[pos+1]))){ //错误示范: //s.replace(pos,9,"you"); s.replace(pos,1,"you"); } } for(int pos=0; ; pos++){ pos=s.find("me",pos); if(pos==-1) break; if((!pos || !isalnum(s[pos-1])) && (pos+2==s.size() || !isalnum(s[pos+2]))){ s.replace(pos,2,"you"); } } f(i,0,s.size()){ if(s[i]=='?')s[i]='!'; else if(s[i]=='A')s[i]='I'; } return s; } int main(){ cin>>n; getchar(); string s; f(line,0,n){ getline(cin,s); cout<<

    推荐阅读