codeforce Lexicographically Maximum Subsequence
2015-02-04 22:24
323 查看
只要读懂题意应该就没问题了吧。。找字符串的字典序最大子序,从后往前找比较方便,最后逆序输出
/*********************************************** * Author: fisty * Created Time: 2015/2/4 21:15:20 * File Name : 3_D.cpp *********************************************** */ #include <iostream> #include <cstring> #include <deque> #include <cmath> #include <queue> #include <stack> #include <list> #include <map> #include <set> #include <string> #include <vector> #include <cstdio> #include <bitset> #include <algorithm> using namespace std; #define Debug(x) cout << #x << " " << x <<endl #define Memset(x, a) memset(x, a, sizeof(x)) const int INF = 0x3f3f3f3f; typedef long long LL; typedef pair<int, int> P; #define FOR(i, a, b) for(int i = a;i < b; i++) #define MAX_N 1000100 int main() { //freopen("in.txt", "r", stdin); //cin.tie(0); //ios::sync_with_stdio(false); char s[MAX_N]; char ans[MAX_N]; while(scanf("%s",s) != EOF){ char max = 0; int len = 0; for(int i = strlen(s)-1;i >= 0; i--){ if(s[i] >= max){ max = s[i]; ans[len++] = s[i]; } } for(int i = strlen(ans)-1; i >= 0; i--){ cout << ans[i]; } cout << endl; } return 0; }
相关文章推荐
- Lexicographically Maximum Subsequence CodeForces - 197C 单调栈
- Codeforces Round #124 (Div. 2) / C. Lexicographically Maximum Subsequence
- Codeforces 124c Lexicographically Maximum Subsequence
- Educational Codeforces Round 32:E. Maximum Subsequence(Meet-in-the-middle)
- codeforce Maximum of Maximums of Minimums(区间划分 求区间最小值最大值问题)
- 【Codeforces Round #172】Codeforces 280D k-Maximum Subsequence Sum
- codeforce.Vladik and flights
- codeforce 939E 差分+二分/三分
- Codeforce Flea CodeForces - 32C 规律|思维
- CodeForce 439C Devu and Partitioning of the Array(模拟)
- Codechef Maximum Weight Difference题解
- PAT_1007: Maximum Subsequence Sum
- Codeforce Bubble Cup 8 - Finals D Tablecity
- Educational Codeforces Round 9 D. Longest Subsequence dp
- codeforce#420 E. Okabe and El Psy Kongroo(图论+矩阵快速幂)
- codeforce 44E Anfisa the Monkey (记忆搜索)
- codeforce C. Okabe and Boxes
- codeforce 149D Coloring Brackets 区间DP
- codeforce round 399# C
- codeforce 148->A. Insomnia cure