题解 | 吐泡泡
吐泡泡
https://www.nowcoder.com/practice/f86fa2221c094b3d8d1fc79bae450d96
#include<iostream>
using namespace std;
#include<string>
#include<stack>
int main(){
int n;
cin >> n;
while (n--) {
string s;
cin>>s;
stack<char>sta;
for(int i=0;i<s.size();i++){
if(s[i]=='o'){
if(sta.empty()||sta.top()!=s[i]){
sta.push(s[i]);
}else if(!sta.empty()&&sta.top()==s[i]){
sta.pop();
if(!sta.empty()&&sta.top()=='O'){
sta.pop();
}
else{
sta.push('O');
}
}
}
if(s[i]=='O'){
if(sta.empty()||sta.top()!=s[i]){
sta.push('O');
}
else if(!sta.empty()&&sta.top()==s[i]){
sta.pop();
}
}
}
stack<char>temp;
while(!sta.empty()){
temp.push(sta.top());
sta.pop();
}
while(!temp.empty()){
cout<<temp.top();
temp.pop();
}
cout<<endl;
}
}
// #include <iostream>
// using namespace std;
// #include<string>
// #include<stack>
// int main() {
// int n;
// cin >> n;
// while (n--) {
// string s;
// stack<char>small;
// stack<char>big;
// cin >> s;
// for (int i = 0; i < s.size(); i++) {
// if (s[i] == 'o') {
// if (small.empty()) {
// small.push('o');
// } else {
// small.pop();
// if(big.empty()){
// big.push('O');
// }
// else{
// big.pop();
// }
// }
// } else if (s[i] == 'O') {
// if (big.empty()) {
// big.push('O');
// } else {
// big.pop();
// }
// }
// }
// while (!small.empty() || !big.empty()) {
// if(!small.empty()){
// cout << small.top();
// small.pop();
// }
// if(!big.empty()){
// cout << big.top();
// big.pop();
// }
// }
// cout<<endl;
// }
// }
// 64 位输出请用 printf("%lld")
