Codeforces Round #279 (Div. 2)E. Restoring Increasing Sequence
来源:互联网 发布:木弹弓制作过程和数据 编辑:程序博客网 时间:2024/05/16 08:12
http://codeforces.com/contest/490/problem/E
字符串处理,思路很快出来,找出符合要求的最近的字符串,如果不存在输出-1,但是实现起来却有点麻烦了,写了半天,不好意思说这个是水题= =。
#include<iostream>#include<algorithm>#include<string>using namespace std;string mtry(string s1,string s2){ /* 找到第一个小的位置 然后向前找?进一位,向后都是0 */ if (s1==s2) return "NULL"; int i=0; for (i=0; i<s1.length(); i++) { if (s1[i]=='?')break; if (s1[i]>s2[i]) { for (int j=0; j<s1.length(); j++) if (s1[j]=='?')s1[j]='0'; return s1; } else if (s1[i]<s2[i]) return "NULL"; else continue; } if (i==s1.length()) return s1; for (i; i<s1.length(); i++) if (s1[i]!='?'&&s1[i]>s2[i]) { for (int j=i; j>=0; j--) if (s1[j]=='?')s1[j]=s2[j]; for (int j=i; j<s1.length(); j++) if (s1[j]=='?')s1[j]='0'; return s1; } else if (s1[i]!='?'&&s1[i]<s2[i]) { int j; for ( j=i; j>=0; j--) if (s1[j]=='?') { if (s2[j]=='9') { s1[j]='0'; continue; } else { s1[j]=s2[j]+1; for (int k=j-1; k>=0; k--) if (s1[k]=='?')s1[k]=s2[k]; for (int k=j+1; k<s1.length(); k++) if (s1[k]=='?') s1[k]='0'; return s1; } } if (j==-1) return "NULL"; } if (i==s1.length()) { int j; for (j=i-1; j>=0; j--) if (s1[j]=='?') { if (s2[j]=='9') { s1[j]='0'; continue; } else { s1[j]=s2[j]+1; for (int k=j-1; k>=0; k--) if (s1[k]=='?')s1[k]=s2[k]; return s1; } } if (j==-1) return "NULL"; } return "NULL";}string ans[100001];int main(){ string s,s1; int cnt=0; s1="0"; int n; cin>>n; for (int i=0; i<n; i++) { cin>>s; if (s.length()<s1.length()) { cout<<"NO"<<endl; return 0; } if (s.length()>s1.length()) { if (s[0]=='?') s[0]='1'; for (int i=1; i<s.length(); i++) if (s[i]=='?')s[i]='0'; ans[cnt++]=s; } if (s.length()==s1.length()) { s=mtry(s,s1); if (s=="NULL") { cout<<"NO"<<endl; return 0; } else ans[cnt++]=s; } s1=s; } cout<<"YES"<<endl; for (int i=0; i<cnt; i++) cout<<ans[i]<<endl; return 0;}
0 0
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence
- Codeforces Round #279 (Div. 2)E. Restoring Increasing Sequence
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence
- Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分
- CodeForces 490E Restoring Increasing Sequence
- CodeForces 490E Restoring Increasing Sequence
- Codeforces 490E Restoring Increasing Sequence(贪心)
- Codeforces 490E. Restoring Increasing Sequence 二分
- CodeForces 490E Restoring Increasing Sequence(贪心)
- CodeForces 490E Restoring Increasing Sequence
- codeforces 490E Restoring Increasing Sequence(贪心)
- Codeforces 490E Restoring Increasing Sequence【二分+模拟】细节题
- Codeforces Round #277 (Div. 2) E. LIS of Sequence
- Codeforces Round #277 (Div. 2) E. LIS of Sequence
- Codeforces Round #278 (Div. 2) E. Prefix Product Sequence
- Codeforces Round #279 (Div. 2) E
- Codeforces Round #279 (Div. 2) E
- Codeforces Round #353 (Div. 2)-B. Restoring Painting(数学)
- 初步理解MySQL(5.6)的执行计划
- iOS中 网络请求( HTTP )小结
- pair源码以及STL - using pair
- 图像旋转算法与实现
- [Python]NumPy函数库
- Codeforces Round #279 (Div. 2)E. Restoring Increasing Sequence
- HDOJ 1875 畅通工程再续---最小生成树问题
- c++
- Android中shape的使用
- Rstudio shortcuts
- 咋样才让不审核~~~~
- OpenCV 实践程序16——提取视频每一帧及用多张图片合成视频
- 汇编指令b和bl区别
- hackerrank_Permutation game