Answer to question-1
#include <bits/stdc++.h> using namespace std;
int main() { string s; cin>>s; stack<char> st; for(int i=0;i<s.size();i++) { if(st.size()==0 || st.top()!=s[i]) { st.push(s[i]); } else { st.pop(); } } if(st.size()==0) { cout<<"Empty String"; } else { string x=""; while(!st.empty()) { x+=st.top(); st.pop(); } reverse(x.begin(),x.end()); cout<<x; } return 0; }
add the test cases for question 2 !!!
Login before adding your answer.
Answer to question-1
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
stack<char> st;
for(int i=0;i<s.size();i++)
{
if(st.size()==0 || st.top()!=s[i])
{
st.push(s[i]);
}
else
{
st.pop();
}
}
if(st.size()==0)
{
cout<<"Empty String";
}
else
{
string x="";
while(!st.empty())
{
x+=st.top();
st.pop();
}
reverse(x.begin(),x.end());
cout<<x;
}
return 0;
}