#include<stdio.h>
#include<stdlib.h>
#define Stack_size 10000
typedef struct{
char elem[Stack_size];
int top;
}seqStack;
void initStack(seqStack *s){
s->top=-1;
}
int isEmpty(seqStack *s){
if(s->top==-1)
return -1;
else
return 0;
}
int push(seqStack *s,char c)
{
if(s->topStack_size)
{
printf(“栈已满”);
return s->top;
}
s->top++;
s->elem[s->top]=c;
return s->top;
}
int pop(seqStack *s)
{
if((s->top)-1)
return s->top;
else
{
s->top–;
return s->top;
}
}
int match(char a,char b)
{
if(a+1b||a+2b)//(+1==),{/[+2==]/}
{
return 1;
}
else
return 0;
}
int BracketMatch(char *str)
{
seqStack s;
int i,top;
initStack(&s);//初始化顺序表
for(i=0;str[i]!=’\0’;i++)
{
printf("%c\n",str[i]);
switch(str[i]){
case’(’:
case’{’:
case’[’:
top=push(&s,str[i]);
printf("%d\n",top);
break;
case’)’:
case’}’:
case’]’:
if(isEmpty(&s)==-1){
printf(“未匹配\n”);
return 0;
}
else{
if(match(str[top],str[i])==1)
top=pop(&s);
else
{
printf(“未匹配\n”);
return 0;
}
}
}
}
if(isEmpty(&s)==-1)
printf(“匹配\n”);
else
printf(“未匹配\n”);
return 0;
}
int main()
{
int n;
char a[10000];
scanf("%d",&n);
while(n–)
{
scanf("%s",a);
BracketMatch(a);
}
return 0;
}