题解 | 好串
好串
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;
}
查看14道真题和解析