### 题目描述

typedef struct
{
char date[Max];
int top;
} Spstack;

1、bool Pop(Spstack *&s,char &e);    //出栈
2、bool GetTop(Spstack *s,char &e); //取栈顶元素
3、bool Push(Spstack *&s,char e);     //入栈
4、bool StackEmpty(Spstack *s);        //判断是否为空栈

{[][]()([])}[]()

Yes

{[()[]][}]

No

1、注意括号匹配问题

2、只需提交你所编写的算法

### 代码如下

``````#include <stdio.h>
#define Max 105
typedef struct
{
char date[Max];
int top;
} Spstack;
void InitStack(Spstack *&s)
{
s= new Spstack;
s->top=-1;
}
bool StackEmpty(Spstack *s)
{
return(s->top==-1);
}
bool Push(Spstack *&s,char e)
{
if(s->top==Max-1)return false;
s->top++;
s->date[s->top]=e;
return true;
}
bool GetTop(Spstack *s,char &e)
{
if(s->top==-1)return false;
e=s->date[s->top];
return true;
}
bool Pop(Spstack *&s,char &e)
{
if(s->top==-1)return false;
e=s->date[s->top];
s->top--;
return true;
}
void DestroyStack(Spstack * &s)
{
delete(s);
}int solve(char *a,Spstack *st)
{
int i=0,match=1;
char e;
while(a[i]!=''&&match)
{
if(a[i]=='('||a[i]=='{'||a[i]=='[')Push(st,a[i]);
else if(a[i]==')'||a[i]=='}'||a[i]==']')
{
if(a[i]==')'&&GetTop(st,e)==true)
{
if(e!='(') match=false;
else Pop(st,e);
}
else if(a[i]=='}'&&GetTop(st,e)==true)
{
if(e!='{') match=false;
else Pop(st,e);
}
else if(a[i]==']'&&GetTop(st,e)==true)
{
if(e!='[') match=false;
else Pop(st,e);
}
else  match=false;
}
i++;
}
if(!StackEmpty(st))match=false;
return match;
}
int main()
{
char a[100];
bool match;
Spstack *st;
InitStack(st);
gets(a);
match=solve(a,st);
DestroyStack(st);
if(match)printf("Yes
");
else printf("No
");
return 0;
}``````