fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string str;
  8. cin >> str;
  9. int s = str.size();
  10. int i;
  11. string ans = str;
  12. string ans2 = ans;
  13. int changes = 0;
  14. int changesStart = 0;
  15. //cout << str << " " << ans << " " << ans2 << " ";
  16. for(i = 0; i < s; i++) {
  17. char c;
  18. if(str[i] == 'a')
  19. c = 'z';
  20. else
  21. c = str[i]-1;
  22. ans2[i] = c;
  23. if(ans2 < ans) {
  24. if(i == 0 || changes == 0) {
  25. ans = ans2;
  26. changes++;
  27. changesStart = i;
  28. }
  29. else {
  30. if(changesStart == i-1) {
  31. ans = ans2;
  32. changes++;
  33. changesStart = i;
  34. }
  35. else
  36. break;
  37. }
  38. }
  39. ans2 = ans;
  40. }
  41. cout << ans << endl;
  42. return 0;
  43. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout