View Code of Problem 3913

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

int main(){
	int T;cin>>T;getchar();
	while(T--){
		char s[100000];
		cin>>s;
		int count=0;
		for(int i=0;i<strlen(s);i++){
			if(s[i]=='('){
				count++;
			}
			else{
				count--;
			}
			if(count<0)
				break;
		}
		if(count==0){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
}

Double click to view unformatted code.


Back to problem 3913