View Code of Problem 3913

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
//	stack<char>w;
	cin>>n;
	getchar(); 
	for(int i = 0;i<n;i++){//控制组数 
		stack<char>w;
		int flag = 0;
		string s;
		cin>>s;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='(')w.push(s[i]);
			else{
				if(!w.empty()){  //栈有左括号 
					w.pop(); 
				}else{   //栈空 
					flag = 1;
					break;
				} 
			} 
		}
		if(!w.empty())flag = 1;
		if(flag == 1)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;	
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3913