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 flag1=1;
		for(int i=0;i<s.length();i++){
			if(s[i]=='('){
				int flag=1;
				for(int j=i+1;j<s.length();j++){
					if(s[j]==')'){
						s[j]=0;
						flag=0;
						break;
					}
				}
				if(flag){
					cout<<"No"<<endl;
					flag1=0;break;
				}
			}
			else if(s[i]==')'){
				cout<<"No"<<endl;
				flag1=0;break;
			}	
		}
		if(flag1){
			cout<<"Yes"<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 3913