#include<bits/stdc++.h>
using namespace std;
template <class T>
struct Node
{
T data;
Node<T> *next;
};
template<class T>///定义栈
class LinkStack
{
private:
Node<T> *top;
public:
LinkStack(){top=NULL;}
~LinkStack();
void Push(T x);
void Pop();
T Get_Top();
int Empty(){if(top==NULL) return 1;return 0;}
};
/* 析构函数 */
template<class T>
LinkStack<T>::~LinkStack()
{
while(top)
{
Node<T> *p;
p=top;
top=top->next;
delete p;
}
}
/* 入栈 */
template<class T>
void LinkStack<T>::Push(T x)
{
Node<T> *s;
s=new Node<T>;
s->data=x;
s->next=top;
top=s;
}
/* 删除 */
template<class T>
void LinkStack<T>::Pop()///注意此处的pop删除有返回值,而STL里面没有,此题不需要可忽略
{
if(top==NULL) throw "下溢";
T x=top->data;
Node<T> *p;
p=top;
top=top->next;
delete p;
return ; //return x;
}
/* 出栈 */
template<class T>
T LinkStack<T>::Get_Top()
{
if(top==NULL) throw "栈空";
return top->data;
}
char str[1000];
void match(LinkStack<char>&s,char str[])
{
char e;
for(int i=0;str[i]!=NULL;i++)
{
switch(str[i])
{
case '(':
case '[':
case '{':
s.Push(str[i]);
break;
case ')':
case ']':
case '}':
if(s.Empty()){
printf("Extra right brackets
");
return ;
}
else
e=s.Get_Top();
if(e=='('&&str[i]==')'||e=='['&&str[i]==']'||e=='{'&&str[i]=='}')
{
s.Pop();
break;
}
else
{
printf("Brackets not match
");
return ;
}
}
}
if(s.Empty())
{
printf("Brackets match
");
}
else
{
printf("Extra left brackets
");
}
}
int main()
{
LinkStack<char> My_stack;
cin>>str;
match(My_stack,str);
return 0;
}