题解 | #好串#
好串
https://ac.nowcoder.com/acm/problem/21874
转化为:括号匹配
Code
#include <bits/stdc++.h> using namespace std; const int N = 100; char s[N]; int main(){ cin>>s+1; int d=0; bool op=false; for(int i=1;s[i];i++){ if(s[i]=='a') d++; else { if(d<=0) op=true; d--; } } if(op||d) puts("Bad"); else puts("Good"); return 0; }