View Code of Problem 3913

#include<stdio.h>
#include<string.h>
#include<math.h>

int main() {
	int T,i;
	scanf("%d",&T);
	while(T--){
		char a[100000];
		int count=0,flag=0;
		scanf("%s",a);
		for(i=0;i<strlen(a);i++){
			if(a[i]=='('){
				count++;
			}else{
				count--;
			}
			
			if(count<0){
				flag=1;
				break;
			}
		}
		if(count!=0){
			flag=1;
		}
		
		if(flag==0){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 3913