注意的点:输入要求中有输入多组数据

思路:将每一即将存入的字符都和栈顶结合。如果相同并且都为O那么出栈;如果相同并且同为o那么出栈,如果此时栈不为空并且栈顶为O那么出栈,否则将O圧栈。如果栈为空那么圧栈。

#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
    string str;
    stack<char> st;
	char c[1000]; 
	while(cin >> str){
		for(int i = 0; i < str.size(); i++){
        if(st.empty()) st.push(str[i]);
        else if(st.top() == 'o' && str[i] == 'o') {
            st.pop();
            if(!st.empty() && st.top() =='O'){
                st.pop();
            }
            else st.push('O');
        }
        else if(st.top() == 'O' && str[i] == 'O') st.pop();
        else if(st.top() != str[i]) st.push(str[i]);
    }
    string a;
	while(!st.empty()){
	    a.push_back(st.top());
	    st.pop();
	}
	for(int i=a.length()-1;i>=0;i--)cout<<a[i];
	cout<<endl;
    }
}