题解 | 好串

好串

https://www.nowcoder.com/practice/9b072237ebdd4dd99562f01cbf594fac

#include <bits/stdc++.h>
using namespace std;

int main() {
    stack<char> a1;

    string s;
    cin >> s;

    for(char x : s){
        if(x == 'b' && !a1.empty() && a1.top() == 'a'){
            a1.pop();
        }else{
            a1.push(x);//只要b进入栈,栈就不可能空了,输出一定为Bad
        }
    }

    if(a1.empty()){
        cout << "Good" << endl;
    }
    else cout << "Bad" << endl;
    return 0;
}

全部评论

相关推荐

对空六翼:你真幸运,碰见这么好的人,不像我,秋招的时候被室友骗进cx了
实习好累,可以辞职全力准...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务