您的位置:首页 > 产品设计 > UI/UE

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: