题意:给出一个字符串,输出子串中字典序最大的一个
链接:http://codeforces.com/problemset/problem/197/C
思路:倒序查找,找出最长非降序序列即可
注意点:无
以下为AC代码:
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged |
---|---|---|---|---|---|---|---|---|
9722495 | Practice: luminous11 | 197C - 30 | GNU C++11 | Accepted | 92 ms | 1948 KB | 2015-02-05 03:44:15 | 2015-02-05 03:44:15 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
int main()
{
char str[1000005];
while ( cin >> str ){
char tmp[1000005];
int len = strlen ( str );
tmp[0] = str[len-1];
int cnt = 0;
for ( int i = len - 2; i >= 0; i -- ){
if ( str[i] >= tmp[cnt] ){
tmp[++cnt] = str[i];
}
}
tmp[++cnt] = 0;
for ( int i = cnt - 1; i >= 0; i -- ){
cout << tmp[i];
}
cout << endl;
}
}