Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<iostream>
- #include<string>
- using namespace std;
- void removeString(string str)
- {
- stack<char>s;
- s.push(str[0]);
- for(int i=1; i<str.length(); i++)
- {
- if(s.empty())
- {
- s.push(str[i]);
- }
- else if(!s.empty()&&str[i]!=s.top())
- {
- s.push(str[i]);
- }
- else if(str[i]==s.top())
- {
- s.pop();
- }
- }
- int j=0;
- char a[100];
- while (!s.empty())
- {
- a[j]=s.top();
- s.pop();
- j++;
- }
- for(int k=(j-1);k>=0;k--)
- {
- cout << a[k];
- }
- }
- int main()
- {
- string str;
- getline(cin,str);
- removeString(str);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement