View Code of Problem 3913

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int flag=0,t=0;
		for(int j=0;j<s.size();j++){
			if(s[j]=='(') t++;
			else if(s[j]==')') t--;
			if(t<0){
				flag=1;
				break;
			}	
		}
		if(t==0&&flag==0){
			cout<<"Yes"<<endl;
		}
		else cout<<"No"<<endl;
	
	}
}

Double click to view unformatted code.


Back to problem 3913