U199256 括号 求助
查看原帖
U199256 括号 求助
1303746
Internet_Explorer_14楼主2024/11/3 14:56

U199256 括号 code:

#include<iostream>
#include<stack>
using namespace std;
bool foo(){
	stack<bool>my_stack;
	string s;
	cin>>s;
	for(auto it=s.begin();it!=s.end();it++){
		if(*it=='('){
			my_stack.push(false);
		}else if(*it==')'){
			if(my_stack.empty()){
				return 0;
			}else{
				my_stack.pop();
			}
		}
	}
	return 1;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	for(int i=1;i<=3;i++){
		cout<<(foo()?"Yes":"No")<<'\n';
	}
	return 0;
}

玄关

2024/11/3 14:56
加载中...