Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define mxx LLONG_MAX
- #define mnn LLONG_MIN
- #define Y() cout<< "YES" <<endl
- #define N() cout << "NO"<<endl
- #define endl "\n"
- #define max_3(a,b,c) max(a, max(b,c))
- #define min_3(a,b,c) min(a, min(b,c))
- #define gcd(a,b) __gcd(a,b)
- #define lcm(a,b) (a*b)/gcd(a,b)
- #define loser return 0
- #define ll long long
- #define PI acos(-1)
- #define mem(a,v) memset(a,v,sizeof(a))
- #define SORT(v) sort(v.begin(),v.end())
- #define REV(v) reverse(v.begin(),v.end())
- #define B begin()
- #define E end()
- #define V vector
- #define F first
- #define S second
- #define PSB push_back
- #define MP make_pair
- #define flash cout.flush()
- #define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
- /*------------------START---------------------*/
- ll cnt[30];
- string ss[30];
- /*-----*/
- void solve(){
- ll n,ans=0;
- string s,answer;
- cin>>s;
- ll len=s.length();
- for(ll i=0;i<len;i++){
- ll ch=s[i]-'a';
- ll mx=0;
- string aux;
- for(ll j=0;j<=ch;j++){
- if((cnt[j])>mx){
- aux=ss[j];
- mx=cnt[j];
- }
- }
- cnt[ch]=++mx;
- aux+=(ch+'a');
- ss[ch]=aux;
- if(cnt[ch]>ans){
- ans=cnt[ch];
- answer=ss[ch];
- }
- else if(cnt[ch]==ans)
- answer=min(answer,ss[ch]);
- }
- cout<<ans<<endl;
- cout<<answer<<endl;
- }
- /*-----*/
- int main(){
- InTheNameOfGod
- ll Test=1;
- //cin>>Test;
- while(Test--){
- solve();
- }
- loser;
- }
- /////// C O D I N G I S L I F E ///////
Advertisement
Add Comment
Please, Sign In to add comment