fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int main() {
  7. string s;
  8. cin >> s;
  9.  
  10. vector<bool> u(26, false);
  11. for (char c : s) {
  12. u[c - 'a'] = true;
  13. }
  14.  
  15. vector<bool> v(26, false);
  16.  
  17. int n = s.size();
  18.  
  19. for (int i = 0; i < n; ++i) {
  20. int c = s[i] - 'a';
  21.  
  22.  
  23. for (int k = 0; k < c; ++k) {
  24.  
  25. if (u[k] && !v[k]) {
  26.  
  27. char x = s[i];
  28. char y = (char)('a' + k);
  29.  
  30. for (int j = 0; j < n; ++j) {
  31. if (s[j] == x) {
  32. s[j] = y;
  33. } else if (s[j] == y) {
  34. s[j] = x;
  35. }
  36. }
  37.  
  38. cout << s;
  39. return 0;
  40. }
  41. }
  42.  
  43. v[c] = true;
  44. }
  45.  
  46. cout << s;
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty