fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. string s; cin >> s;
  9. int n = s.size();
  10. s += '#';
  11. char last = '-';
  12. for (int i = 0; i < n; i++) {
  13. int j = i;
  14. while (s[j] == s[i]) j++;
  15. j--;
  16.  
  17. if (i == j) { last = s[i]; continue;}
  18.  
  19. string t = "!!";
  20. int k = 0;
  21. for (char ch = 'a'; ch <= 'z' && k < 2; ch++)
  22. if (ch != s[i] && ch != last && ch != s[j+1]) t[k++] = ch;
  23. last = s[i];
  24. k = 0;
  25. for (int l = i+1; l <= j; l+=2)
  26. s[l] = t[k], k ^= 1;
  27.  
  28. i = j;
  29. }
  30. s.pop_back();
  31.  
  32. cout << s << endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5312KB
stdin
caaab
stdout
cadab