View Code of Problem 3913

#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>
int pipei(char lift, char right)
{
	if (lift == '('&&right == ')')
		return 1;
	if (lift == '['&&right == ']')
		return 1;
	if (lift == '{'&&right == '}')
		return 1;
	return 0;
}
int main()
{
	char a[100000];
	int i, j, n;
	scanf("%d", &n);
	char ch;
	int flag=1;
	while (n--)
	{
		getchar();
		gets(a);
		char b[100000];
		int top = -1;
		flag = 1;
		for (i = 0; a[i] != '\0'; i++)
		{
			if (a[i] == '(' || a[i] == '[' || a[i] == '{')
			{
				b[++top] = a[i];
			}
			if (a[i] == ')' || a[i] == ']' || a[i] == '}')
			{
				if (top == -1)
				{
					flag = 0;
					break;
				}
				j = pipei(b[top--], a[i]);
				if (j == 0)
				{
					flag = 0;
					break;
				}
			}
				
				
		}
		if (flag==1)
			printf("Yes\n");
		else printf("No\n");
	}
		return 0;
}

Double click to view unformatted code.


Back to problem 3913