fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. string f(string s) {
  5.  
  6. string rs = "";
  7.  
  8. int j = 1;
  9. int n = s.length();
  10.  
  11. for (int i=0;i<n;i++) {
  12. if (s[i] == s[j]) {
  13. j++;
  14. i--;
  15. } else {
  16. if (j - i > 1) {
  17. i = j - 1;
  18. } else {
  19. rs += s[i];
  20. }
  21. }
  22. }
  23.  
  24. return rs;
  25. }
  26.  
  27. int main() {
  28.  
  29. string s;
  30. cin>>s;
  31.  
  32. cout<<f(s)<<endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 4508KB
stdin
abcccd
stdout
abd