View Code of Problem 3913

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 100
using namespace std;
int ismatch(char a,char b){
	if(a=='('&&b==')'){
		return 1;
	}else if(a=='['&&b==']'){
		return 1;
	}else if(a=='{'&&b=='}'){
		return 1;
	}else{
		return 0;
	}
}
int main()
{
	int t;
	cin>>t;
	while(t--){
		getchar();
		char a[100000];
		cin>>a;
		int k=0,flag=0;
		for(int i=0;i<strlen(a);i++){
		if(a[i]=='('){
			k++;
		}else if(a[i]==')'&&k>0){
			k--;
		}else if(a[i]==')'&&k<=0){	
		     flag=1;
		     break;
		}
	}	
	if(flag==0&&k==0){
			cout<<"Yes"<<endl;
		}
		else
		cout<<"No"<<endl;
		
}
return 0;
}

Double click to view unformatted code.


Back to problem 3913