View Code of Problem 3913

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

int main()
{
	int n;
	scanf("%d",&n); 
	for(int i=0;i<n;i++)
	{
		int left=0;
		int flag=1;
		char str[99999];
		scanf("%s",str);
		for(int j=0;j<strlen(str);j++)
		{
			if(str[j]=='(')
			{
				left++;
			}
			else
			{
				left--;
			}
			if(left<0)
			{
				flag=0;
				break;
			}
		}
		if(left!=0)
		{
			flag=0;
		}
		
		if(flag)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3913