View Code of Problem 3913

#include <iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		string s;
		cin>>s;
		int left=0,right=0,flag=1;
		for(int i=0;i<s.length();i++){
			if(s[i]=='(')
				left++;
			else if(s[i]==')')
				right++;
			if(right>left){
				flag=0;
				break;
			}
		}
		if(left!=right)
			flag=0;
		if(flag)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3913