题解 | 好串

好串

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

#include <stdio.h>
#include<string.h>
int main() {
    char s[100002];
    char stack[100001];
    int top=0;
    scanf("%s",s);
    for(int i=0;s[i]!='\0';i++){
        if(s[i]=='b'&&top>0&&stack[top-1]=='a'){
            top--;
        }
        else{
            stack[top++]=s[i];
        }
    }
    if(top==0) printf("Good\n");
    else printf("Bad\n");
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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