fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const int MAX_LENGTH = 101;
  7.  
  8. int main() {
  9. char s[MAX_LENGTH];
  10. cin >> s;
  11. char maxS[MAX_LENGTH];
  12. strcpy(maxS, s);
  13. int size = strlen(s);
  14. int start = size - 1;
  15. bool found = false;
  16. for(int i = 0; i < size and !found; i++){
  17. for(int j = i; j < size; j++){
  18. if(s[j] > s[i]){
  19. start = i;
  20. found = true;
  21. break;
  22. }
  23. }
  24. }
  25. for(int j = start + 1; j < size; j++){
  26. if(s[j] >= s[start]) {
  27. char curMax[MAX_LENGTH];
  28. strcpy(curMax, s);
  29. for (int k = j; k < size; k++) {
  30. char temp = s[k];
  31. for(int i = k; i > start + k - j; i--){
  32. curMax[i] = curMax[i - 1];
  33. }
  34. curMax[start + k - j] = temp;
  35. if(strncmp(curMax, maxS, size) > 0){
  36. strcpy(maxS, curMax);
  37. }
  38. }
  39. }
  40. }
  41. cout << maxS;
  42. return 0;
  43. }
Success #stdin #stdout 0s 4364KB
stdin
Standard input is empty
stdout