View Code of Problem 3913

#include<stdio.h>
#include<string.h>
int main(){
	char str[100000],a[10000],b[10000];
	int t,i;
	scanf("%d",&t);
	while(t--){
		memset(a,'\0',sizeof(a));
		memset(b,'\0',sizeof(b));
		scanf("%s",str);
		int k1=0,k2=0;
		int len=strlen(str);
		for(i=0;i<len;i++){
			if(str[i]=='(')
			a[k1++]='(';
			else if(str[i]==')')
			a[k2++]=')';
		}
		if(k1!=k2)
		printf("No\n");
		else{
			int top=-1;
		memset(a,'\0',sizeof(a));
		for(i=0;i<len;i++){
			if(str[i]=='('){
			top++;
			a[top]='(';
		}
			else{
				if(a[top]!='(')
				{
					printf("No\n");
					break;
				}
				else
				top--;
			}
		}
		if(i==len)
		printf("Yes\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 3913