【牛客】牛客练习赛16(未完)

A  字典序最大的子序列

题意:给定字符串s,s只包含小写字母,请求出字典序最大的子序列。(看例子就能看明白)

思路:从这个字符串a后面开始比较,先把最后一个字母存进s,然后那那s中最新的一个元素跟a中上一个进行比较,如果a不比s小,则存入s,并把这个看做新哒~

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
char s[100007];
int main() 
{

    string a;
    while(cin>>a){
        int i,t;
        s[0]=a[a.length()-1];
        t=0;
       // cout<<a.length()<<endl;
        for(i=a.length()-2;i>=0;i--){
            if(a[i]>=s[t]){
                s[++t]=a[i];

            }
        }
        for(;t>=0;t--){
            cout<<s[t];
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Kohinur/p/8982479.html
今日推荐