CF(#293 div2):A:Vitaly and Strings
2015-03-02 22:38
543 查看
题目链接:http://codeforces.com/contest/518/problem/A
题目讲的大意是,给出两个等长字符串s,t,求出任意一个字典序介于两者之间的任意一个等长字符串。题意很简单。但容易出错,被hacked了,最后还WA了好几次。值的记录一下。
代码及详解:
题目讲的大意是,给出两个等长字符串s,t,求出任意一个字典序介于两者之间的任意一个等长字符串。题意很简单。但容易出错,被hacked了,最后还WA了好几次。值的记录一下。
代码及详解:
//freopen("C:\\Documents and Settings\\All Users\\桌面\\in.txt","w",stdout); #include<iostream> #include<sstream> #include<cstdio> #include<cmath>} #include<cstring> #include<algorithm> #include<string> using namespace std; string s,t; int main(){ //freopen("C:\\Documents and Settings\\All Users\\桌面\\kk.txt","r",stdin); while(cin>>s){ cin>>t; int cnt; for(cnt=0;cnt<s.size();cnt++) if(s[cnt]!=t[cnt]) break; if(s[cnt]+1<t[cnt]){s[cnt]=s[cnt]+1;cout<<s<<endl;continue;}//如果这两个字符不相连可以直接得出答案 else{//则第cnt个字符只能存在于s段或t段 int i=1,op=0; while(t[cnt+i]){//先看t段,如果t后面的字符不全为'a'则,可由t段得出答案 if(t[cnt+i]!='a') {t[cnt+i]='a';cout<<t<<endl;op=1;break;} i++; } if(op) continue; i=1;op=0; while(s[cnt+i]){//再看s段,如果s段不全为'z',则可由s段得出答案 if(s[cnt+i]!='z') {s[cnt+i]='z';cout<<s<<endl;op=1;break;} i++; } if(op) continue; cout<<"No such string\n"; } } return 0; }
相关文章推荐
- Codeforces Round #293 (Div. 2)——A—— Vitaly and Strings
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings(思路)
- Codeforces Round #293 (Div. 2) -- A. Vitaly and Strings (字符串构造)
- CF 293 A. Vitaly and Strings
- CF 226 DIV2 B. Bear and Strings
- Codeforces Round #293 (Div. 2)A. Vitaly and Strings
- CF Vitaly and Strings
- CF 518A(Vitaly and Strings-构造)
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings
- codeforces 293 dvi2 A. Vitaly and Strings
- Codeforces Round #293 (Div. 2) -- A. Vitaly and Strings
- Codeforces Round #293 (Div. 2)--A-- Vitaly and Strings - Painting
- Codeforces Round #226 (Div. 2) B. Bear and Strings
- Codeforces Round #358 (Div. 2) Alyona and Strings
- 518A - Vitaly and Strings【string】
- codeforces 518 A. Vitaly and Strings
- Codeforces #410(div2) B. Mike and strings (暴力枚举
- CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and
- CF#195(div2) A:Vasily the Bear and Triangle