// 09E.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int _tmain(int argc, _TCHAR* argv[])
{
int num,i,j,top;
char array[100],stack[100];
int flag[100];
scanf_s("%d\n",&num);
for(i=0;i<num;i++)
{
j=top=0;
gets_s(array);
while(array[j])
{
if(array[j]=='('||array[j]==')'||array[j]=='['||array[j]==']'||array[j]=='{'||array[j]=='}')
{
stack[top++]=array[j];
if(top>=2)
{
if(stack[top-2]=='('&&stack[top-1]==')'||stack[top-2]=='['&&stack[top-1]==']'||stack[top-2]=='{'&&stack[top-1]=='}')
{
top-=2;
}
}
}
j++;
}
if(top==0)
flag[i]=1;
else
flag[i]=0;
}
for(i=0;i<num;i++)
{
if(flag[i])
printf("yes\n");
else
printf("no\n");
}
system("pause");
return 0;
}
//
#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
int _tmain(int argc, _TCHAR* argv[])
{
int num,i,j,top;
char array[100],stack[100];
int flag[100];
scanf_s("%d\n",&num);
for(i=0;i<num;i++)
{
j=top=0;
gets_s(array);
while(array[j])
{
if(array[j]=='('||array[j]==')'||array[j]=='['||array[j]==']'||array[j]=='{'||array[j]=='}')
{
stack[top++]=array[j];
if(top>=2)
{
if(stack[top-2]=='('&&stack[top-1]==')'||stack[top-2]=='['&&stack[top-1]==']'||stack[top-2]=='{'&&stack[top-1]=='}')
{
top-=2;
}
}
}
j++;
}
if(top==0)
flag[i]=1;
else
flag[i]=0;
}
for(i=0;i<num;i++)
{
if(flag[i])
printf("yes\n");
else
printf("no\n");
}
system("pause");
return 0;
}