#include <stdio.h>
#include <string.h>
#define M 50
typedef struct node{
char data[M];
int top;
}SqStack;
void InitStack(SqStack &S){
S.top=-1;
}
bool StackEmpty(SqStack &S){
if(S.top==-1){
return true;
}
else{
return false;
}
}
bool Push(SqStack &S,char e){
if(S.top==M-1){
return false;
}
S.data[++S.top]=e;
return true;
}
bool Pop(SqStack &S,char &x){
if(S.top==-1){
return false;
}
x=S.data[S.top--];
return true;
}
bool GetTop(SqStack &S,char &x){
if(S.top==-1){
return false;
}
x=S.data[S.top];
}
void Init(){
}
bool bracketCheck(char str[],int length){
SqStack S;
InitStack(S);
for(int i=0;i<length-1;i++){
if(str[i]=='{' || str[i]=='[' || str[i]=='('){
Push(S,str[i]);
}
else{
if(StackEmpty(S)){
return false;
}
char top;
Pop(S,top);
if(str[i]=='(' && top!=')'){
return false;
}
if(str[i]=='[' && top!=']'){
return false;
}
if(str[i]=='{' && top!='}'){
return false;
}
}
}
return StackEmpty(S);
}
int main() {
char s[8]="{{{{}}}";
printf("%d",bracketCheck(s,8));
return 0;
}