题解 | 好串
好串
https://www.nowcoder.com/practice/9b072237ebdd4dd99562f01cbf594fac
#include <stdio.h>
#include<string.h>
#include<stdbool.h>
int main() {
char a[100005];
bool yes=true;
scanf("%s",a);
int top=0;
int m=strlen(a);
char stack[10005];
for(int i=0;i<m;i++){
if(a[i]=='a'){
stack[top++]=a[i];
}
else if(a[i]=='b'){
if(top==0||stack[top-1]!='a'){
yes=false;
break;
}
top--;
}
}
if(top!=0){
yes=false;
}
if(yes){
printf("Good\n");
}
else{
printf("Bad");
}
return 0;
}
查看9道真题和解析