fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t;
  8. cin>>t;
  9. ios::sync_with_stdio(false);
  10.  
  11.  
  12. while(t--)
  13. {
  14. char kolejka[1000000];
  15. cin>> kolejka;
  16. int rozmiar = strlen(kolejka);
  17. int maks = kolejka[rozmiar-1];
  18.  
  19. for(int i = rozmiar - 1; i > 0; i-- )
  20. {
  21. if(kolejka[i-1] < maks)
  22. for(int x=0; x < rozmiar; x++)
  23. kolejka[x] = kolejka[x+1];
  24.  
  25. else if ( kolejka[i-1] > maks)
  26. maks = kolejka[i-1];
  27. }
  28. for(int x=0; x < rozmiar; x++)
  29. cout<<kolejka[x];
  30.  
  31. cout<<endl;
  32.  
  33. }
  34.  
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 4400KB
stdin
2
klkkn
klKKnNLlNL
stdout
n
lNL