View Code of Problem 3913

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

int main(){
	int T;cin>>T;getchar();
	while(T--){
		string s;
		cin>>s;
		int count=0;
		int flag=0;
		int flag1=0;
		for(int i=0;i<s.length();i++){
			if(s[i]=='('){
				count++;flag=1;
			}
			else if(s[i]==')'&&flag==1){
				count--;
			}
			if(count<0){
				cout<<"No"<<endl;flag1=1;break;
			}
		}
		if(count==0&&flag1==0){
			cout<<"Yes"<<endl;
		}
		else if(count!=0&&flag1==0){
			cout<<"No"<<endl;
		}
		else if(flag1==1){
			continue;
		}
	}
}

Double click to view unformatted code.


Back to problem 3913