Rudro_Debnath

string1

Sep 23rd, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define mxx LLONG_MAX
  4. #define mnn LLONG_MIN
  5. #define Y() cout<< "YES" <<endl
  6. #define N() cout << "NO"<<endl
  7. #define endl "\n"
  8. #define max_3(a,b,c) max(a, max(b,c))
  9. #define min_3(a,b,c) min(a, min(b,c))
  10. #define gcd(a,b) __gcd(a,b)
  11. #define lcm(a,b) (a*b)/gcd(a,b)
  12. #define loser return 0
  13. #define ll long long
  14. #define PI acos(-1)
  15. #define mem(a,v) memset(a,v,sizeof(a))
  16. #define SORT(v) sort(v.begin(),v.end())
  17. #define REV(v) reverse(v.begin(),v.end())
  18. #define B begin()
  19. #define E end()
  20. #define V vector
  21. #define F first
  22. #define S second
  23. #define PSB push_back
  24. #define MP make_pair
  25. #define flash cout.flush()
  26. #define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  27.  
  28. /*------------------START---------------------*/
  29. ll cnt[30];
  30. string ss[30];
  31. /*-----*/
  32. void solve(){
  33. ll n,ans=0;
  34. string s,answer;
  35. cin>>s;
  36. ll len=s.length();
  37. for(ll i=0;i<len;i++){
  38. ll ch=s[i]-'a';
  39. ll mx=0;
  40. string aux;
  41. for(ll j=0;j<=ch;j++){
  42. if((cnt[j])>mx){
  43. aux=ss[j];
  44. mx=cnt[j];
  45. }
  46. }
  47. cnt[ch]=++mx;
  48. aux+=(ch+'a');
  49. ss[ch]=aux;
  50. if(cnt[ch]>ans){
  51. ans=cnt[ch];
  52. answer=ss[ch];
  53. }
  54. else if(cnt[ch]==ans)
  55. answer=min(answer,ss[ch]);
  56. }
  57. cout<<ans<<endl;
  58. cout<<answer<<endl;
  59.  
  60.  
  61.  
  62. }
  63. /*-----*/
  64. int main(){
  65. InTheNameOfGod
  66.  
  67. ll Test=1;
  68. //cin>>Test;
  69. while(Test--){
  70. solve();
  71. }
  72. loser;
  73.  
  74. }
  75. /////// C O D I N G I S L I F E ///////
  76.  
Advertisement
Add Comment
Please, Sign In to add comment