fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string s;
  8. cin >> s;
  9. string maxS = s;
  10. int start = s.size() - 1;
  11. bool found = false;
  12. for(int i = 0; i < s.size() and !found; i++){
  13. for(int j = i; j < s.size(); j++){
  14. if(s[j] > s[i]){
  15. start = i;
  16. found = true;
  17. break;
  18. }
  19. }
  20. }
  21. for(int j = start + 1; j < s.size(); j++){
  22. if(s[j] >= s[start]) {
  23. string curMax = s;
  24. for (int k = j; k < s.size(); k++) {
  25. curMax.insert(start + k - j, 1, s[k]);
  26. curMax.erase(k + 1, 1);
  27. maxS = max(curMax, maxS);
  28. }
  29. }
  30. }
  31. cout << maxS;
  32. return 0;
  33. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
Standard output is empty