fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define pb push_back
  6. int main()
  7. {
  8. string s;
  9. while(cin>>s)
  10. {
  11. string x,y;
  12. ll n=s.size();
  13. ll j=n-1;
  14. for(ll i=0;i<n;i++)
  15. {
  16. if(s[i]==s[j]){
  17. j--;
  18. x.pb(s[i]);
  19. }
  20. else
  21. {
  22. j=n-1;
  23. y+=x;
  24. y.pb(s[i]);
  25. x.clear();
  26. if(s[i]==s[j]){
  27. y.erase(y.end()-1);
  28. x.pb(s[i]);
  29. j--;
  30. }
  31.  
  32. }
  33. }
  34. reverse(y.begin(),y.end());
  35. s+=y;
  36.  
  37. cout<<s<<endl;
  38. }
  39.  
  40. }
  41.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty