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<<
推荐阅读
- 模拟|UPC-自习课
- 约战蓝桥|蓝桥杯十大常见天阶功法——音之呼吸.肆之型.模拟
- POJ 1027 The Same Game 模拟题
- CodeForces - 1102B(Array K-Coloring(给数字涂颜色))
- CodeForces1102B--Array K-Coloring--思维
- 模拟|【离散化扫描】 校门外的树{加强版}
- codeforce 469 B C -模拟 -构造
- Codeforces Round #531 (Div. 3) D Balanced Ternary String【模拟】
- zoj Capture the Flag 比较难的模拟题