#include <stdio.h>
#include <string.h>
#define LOCAL
char str[130];
char stack[130];
int main()
{
int i, j, n;
int len;
int top;
#ifndef LOCAL
freopen("c://uva_in.txt", "r", stdin);
#endif
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++)
{
gets(str);
len = strlen(str);
if (len == 0)
{
printf("Yes/n");
continue;
}
stack[0] = str[0];
top = 0;
for (j = 1; j < len; j++)
{
if (str[j] == '(' || str[j] == '[')
stack[++top] = str[j];
else if (str[j] == ')')
{
if (top >= 0 && stack[top] == '(')
--top;
else
stack[++top] = str[j];
} else
{
if (top >= 0 && stack[top] == '[')
--top;
else
stack[++top] == str[j];
}
}
if (top == -1)
printf("Yes/n");
else
printf("No/n");
}
return 0;
}
uva673 Parentheses Balance
最新推荐文章于 2022-02-25 19:38:17 发布