题解 | 吐泡泡
吐泡泡
https://www.nowcoder.com/practice/f86fa2221c094b3d8d1fc79bae450d96
#include<bits/stdc++.h>
using namespace std;
int T;
string s;
int main(){
cin>>T;
while(T--){
cin>>s;
stack<char> st;
for(int i=0;i<s.size();i++){
if(s[i]=='o'&&(st.empty()||!st.empty()&&st.top()!='o')){
st.push('o');
}else if(s[i]=='o'&&!st.empty()&&st.top()=='o'){
st.pop();
if(!st.empty()&&st.top()=='O'){
st.pop();
}else{
st.push('O');
}
}else if(s[i]=='O'&&(st.empty()||!st.empty()&&st.top()!='O')){
st.push('O');
}else if(s[i]=='O'&&!st.empty()&&st.top()=='O'){
st.pop();
}
}
string res="";
while(!st.empty()){
res=st.top()+res;
st.pop();
}
cout<<res<<endl;
}
return 0;
}

