题解 | 好串

好串

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

#include<bits/stdc++.h>
using namespace std;


string s;
stack<char> st; 

int main(){
	
	cin>>s;
	
	bool flag=true;
	
	for(int i=0;i<s.size();i++){
		if(s[i]=='a'){
			st.push(s[i]);
		}else{
			if(st.empty()||st.top()!='a'){
				flag=false;
				break;
			}else{
				st.pop();
			}
		}
	}
	
	if(!st.empty()){
		flag=false;
	}
	
	if(flag){
		cout<<"Good"<<endl;
	}else{
		cout<<"Bad"<<endl;
	}
    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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