牛客题解:吐泡泡(stack)
发布时间
阅读量:
阅读量
//①数据有多组,需要while(cin>>s)循环输入
//②把元素弹出栈的时候需要考虑此时栈是否为空
#include<iostream>
#include<stack>
#include<string>
using namespace std;
char c[105];
int main()
{
string s;
while(cin>>s){
stack<char> st;
st.push(s[0]);
for(int i = 1; i < s.length(); i++){
if(st.empty() || s[i] != st.top()){
st.push(s[i]);
continue;
}
if(!st.empty() && s[i] == st.top()){
if(st.top() == 'o'){
st.pop();
if(!st.empty() && st.top() == 'O'){
st.pop();
}
else{
全部评论 (0)
还没有任何评论哟~
