1.注意要在&&前检查栈是否为空,!s1.empty();
2.连续消时要检查前面是否还有数据
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
string str;
cin>>str;
stack<char>s1;
for(int i=0;i<str.size();i++)
{
if(s1.empty()||s1.top()!=str[i])
{
s1.push(str[i]);
}
else if(s1.top()=='o'&&str[i]=='o')
{
s1.pop();
if(!s1.empty()&&s1.top()=='O')
{
s1.pop();
}
else if((!s1.empty()&&s1.top()=='o')||s1.empty())
{
s1.push('O');
}
}
else if(s1.top()=='O'&&str[i]=='O')
{
s1.pop();
}
}
string str2="";
while(!s1.empty())
{
str2+=s1.top();
s1.pop();
}
reverse(str2.begin(),str2.end());
cout<<str2<<endl;
}
}