A lexicographically largest subsequence
The meaning of the question: Given a string s, s contains only lowercase letters, request the largest subsequence in lexicographical order. (Look at the example to understand)
Idea: Start the comparison from the back of this string a, first store the last letter in s, then compare the latest element in that s with the previous one in a, if a is not smaller than s, store it in s, and put This looks new~
#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; }