【贪心】Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
2017-02-24 21:01
323 查看
从后向前枚举字符串,然后从左向右枚举位。
如果该串的某位比之前的串的该位小,那么将之前的那串截断。
如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度。
具体看代码。
如果该串的某位比之前的串的该位小,那么将之前的那串截断。
如果该串的某位比之前的串的该位大,那么之前那串可以直接保留全长度。
具体看代码。
#include<cstdio> #include<iostream> #include<string> using namespace std; string a[500010]; int n,lens[500010],b[500010]; int main() { // freopen("d.in","r",stdin); scanf("%d",&n); for(int i=1;i<=n;++i) { cin>>a[i]; b[i]=a[i].length(); } lens =b ; for(int i=n;i>1;--i) { bool flag=0; for(int j=0;j<lens[i];++j) { if(j>=b[i-1]) { lens[i-1]=b[i-1]; flag=1; break; } if(a[i][j]<a[i-1][j]) { lens[i-1]=j; flag=1; break; } if(a[i][j]>a[i-1][j]) { lens[i-1]=b[i-1]; flag=1; break; } } if(!flag) lens[i-1]=lens[i]; } for(int i=1;i<=n;++i) { for(int j=0;j<lens[i];++j) putchar(a[i][j]); puts(""); } return 0; }
相关文章推荐
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags【模拟、贪心】
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags 贪心、字符串处理
- Codeforces Round #401 (Div. 2)D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags(暴力)
- Codeforces Round #401(Div. 2)D. Cloud of Hashtags【逆序思维】
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- [CF777D] Cloud of Hashtags(贪心,二分)
- Codeforces Round #401 (Div. 2) D. Cloud of Hashtags
- Codeforces Round #382 (Div. 2)C. Tennis Championship(贪心)
- Codeforces Round #211 (Div. 2) D题(二分,贪心)解题报告
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
- 【Codeforces Round 272 (Div 2)A】【贪心 暴力 水题】Dreamoon and Stairs n个台阶每次走一步或两步是否有步数恰好为m倍数
- Codeforces Round #387 (Div. 2) Winter Is Coming(贪心)
- 【推导】【贪心】Codeforces Round #431 (Div. 1) A. From Y to Y
- Codeforces Round #288 (Div. 2)C. Anya and Ghosts(模拟+贪心)
- Codeforces Round #373 (Div. 2) C. Efim and Strange Grade —— 贪心 + 字符串处理
- Codeforces Round #389 (Div. 2) B. Santa Claus 贪心+字符串处理、易错
- Codefroecs 289 div2 B. Painting Pebbles(贪心)
- Codeforces Round #433 (Div. 2) Jury Meeting(贪心)