/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param s string字符串
* @return bool布尔型
*/
typedef struct {
char a[10000];
char *top,*bottom;
}arr;
void PUT(arr *a,char* s){//入栈
if(a->top==NULL){
a->a[0]=*s;
a->bottom=a->top=a->a;
}else{
*(++a->top)=*s;
}
}
void EXIT(arr *a){//出栈
if(a->top==a->bottom){
a->top=a->bottom=NULL;
}else{
a->top--;
}
}
bool isValid(char* s ) {
// write code here
arr a={{0},NULL,NULL};
if(*s=='{'||*s=='('||*s=='[')
while(*s){
if(*s=='{'||*s=='('||*s=='['){
PUT(&a,s);
}else if(*s==']'||*s==')'||*s=='}'){
if(a.top!=NULL&&((*(a.top)=='{'&&*s=='}')||(*(a.top)=='['&&*s==']')||(*(a.top)=='('&&*s==')'))){
EXIT(&a);
}else {
return false;
}
}
s++;
}
if(!(*s)&&a.top==NULL){
return true;
}
return false;
}