fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. int32_t main()
  5. {
  6. cin.tie(0);
  7. cout.tie(0);
  8. ios::sync_with_stdio(false);
  9. int t=1;
  10. //cin>>t;
  11. while(t--)
  12. {
  13. string s;
  14. vector<char>v;
  15. stack<char> st;
  16. cin>>s;
  17. for(int i=0;i<s.size();i++)
  18. {
  19. if(!st.empty())
  20. {
  21. if(s[i]==st.top())
  22. {
  23. st.pop();
  24. }
  25. else
  26. {
  27. st.push(s[i]);
  28. }
  29. }
  30. else
  31. st.push(s[i]);
  32. }
  33. while(!st.empty())
  34. {
  35. v.push_back(st.top());
  36. st.pop();
  37. }
  38. reverse(v.begin(),v.end());
  39. for(int i=0;i<v.size();i++)
  40. {
  41. cout<<v[i];
  42. }
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty