//”消去“的栈模拟 #include<iostream> #include<stack> using namespace std; int main() { string s; while(cin>>s) { stack<char> st; string str; st.push(s[0]); int len=(int)s.length(); for(int i=1;i<len;i++) { //oo|oO|OO|Oo 栈顶元素和串当前元素的可能情况 if(!st.empty()&&st.top()==s[i]&&s[i]=='o') { st.pop(); if(!st.empty()&&st.top()=='O')//肯定是大O?这地方不加判空出错 st.pop();//注意oo变成O不一定要push一个O进去,出错点 else st.push('O'); } else if(!st.empty()&&st.top()==s[i]&&s[i]=='O') { st.pop(); } else st.push(s[i]); } while(!st.empty())//将栈里剩余的弹出至str中 { str+=st.top(); st.pop(); } for(int i=(int)str.length()-1;i>=0;i--)//逆序输出str cout<<str[i]; cout<<endl; } return 0; }