题解 | 好串
好串
https://www.nowcoder.com/practice/9b072237ebdd4dd99562f01cbf594fac
#include <iostream>
#include <stack>
using namespace std;
bool check(string s){
stack<char> st;
for(int i=0;i<s.length();i++){
if(s[i]=='a'){
st.push(s[i]);
}
else if(s[i]=='b'){
if(st.empty()){
return 0;
}
st.pop();
}
}
return st.empty();
}
int main() {
string s;
cin>>s;
if(check(s)) cout<<"Good";
else cout<<"Bad";
return 0;
}
// 64 位输出请用 printf("%lld")
