话不多说,直接上代码,一个栈就可以全部搞定了!
#include<bits/stdc++.h>
using namespace std;
int main()
{
stack<char> st;
string str;
cin>>str;
for(int i=0;i<str.size();i++)
{
if(st.empty())
{
st.push(str[i]);
}
else
{
if(st.top() == str[i])
st.pop();
else st.push(str[i]);
}
}
if(st.empty()) cout<<0<<endl;
else
{
int n=st.size();
char a[n];
for(int i=n-1;i>=0;i--) {
a[i] = st.top();
st.pop();
}
for(int i=0;i<n;i++) cout<<a[i];
}
return 0;
}