https://ac.nowcoder.com/acm/problem/15029

### Code

```#include <bits/stdc++.h>

using namespace std;

const int N = 110;

char stk[N];
string s;
int hh;

bool check(int h,int i){
if(stk[i]=='o'&&stk[h]=='o') return true;
if(stk[i]=='O'&&stk[h]=='O') return true;
return false;
}

int main(){
while(cin>> s){
hh=0;
for(int i=0;i<s.size();i++){
stk[++hh]=s[i];
while(hh>1&&check(hh,hh-1)){
if(stk[hh]=='o') hh--,stk[hh]='O';
else hh-=2;
}
}
for(int i=1;i<=hh;i++) cout<<stk[i];
puts("");
// hh不再是0,所以需要重新置零
}
return 0;
}```

### Code

```#include <bits/stdc++.h>

using namespace std;

const int N = 110;

string s;

bool check(char c1,char c2){
if(c1==c2) return true;
return false;
}

int main(){
while(cin>> s){
stack<char> stk;
for(int i=0;i<s.size();i++){
stk.push(s[i]);
while(stk.size()>=2){
char c1=stk.top(); stk.pop();
char c2=stk.top(); stk.pop();

stk.push(c2);  stk.push(c1);

if(!check(c1,c2)) break;

if(c1=='o'){
stk.pop();  stk.pop();
stk.push('O');
}
else  stk.pop(),stk.pop();
}
}

string res;
while(stk.size()){
res+=stk.top();
stk.pop();
}
reverse(res.begin(),res.end());
cout<<res<<endl;
// hh不再是0,所以需要重新置零
}

return 0;
}```

2022-12-20 17:21

2022-11-30 10:59

2022-12-26 14:32

01-20 18:57

2022-12-07 01:59

2022-12-09 14:30

2022-12-06 13:45

2022-12-21 15:38

2022-12-07 18:37

1 收藏 评论