Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<string>
  4. using namespace std;
  5.  
  6. void removeString(string str)
  7. {
  8. stack<char>s;
  9. s.push(str[0]);
  10.  
  11. for(int i=1; i<str.length(); i++)
  12. {
  13. if(s.empty())
  14. {
  15. s.push(str[i]);
  16. }
  17. else if(!s.empty()&&str[i]!=s.top())
  18. {
  19. s.push(str[i]);
  20. }
  21. else if(str[i]==s.top())
  22. {
  23. s.pop();
  24. }
  25. }
  26. int j=0;
  27. char a[100];
  28. while (!s.empty())
  29. {
  30. a[j]=s.top();
  31. s.pop();
  32. j++;
  33. }
  34. for(int k=(j-1);k>=0;k--)
  35. {
  36. cout << a[k];
  37. }
  38.  
  39. }
  40.  
  41. int main()
  42. {
  43. string str;
  44. getline(cin,str);
  45. removeString(str);
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement