#include "stdio.h"
#include "stdlib.h"
#define MAXSIZE 100
typedef struct{
char *base;
char *top;
int StackSize;
}sqStack;
int BracketInspect(sqStack *S)
{
char Bracket;
S->StackSize=MAXSIZE;
S->base=(char *)malloc(S->StackSize*sizeof(char));
S->top=S->base;
do{
scanf("%c",&Bracket);
switch(Bracket){
case '(':*S->top++='(';break;
case '[':*S->top++='[';break;
case '{':*S->top++='{';break;
case ')'://以下为右括号的情况
if(S->top==S->base)return 0;
if(*(S->top-1)!='(')return 0;
if(*(S->top-1)=='(')--S->top;break;
case ']':
if(S->top==S->base)return 0;
if(*(S->top-1)!='[')return 0;
if(*(S->top-1)=='[')--S->top;break;
case '}':
if(S->top==S->base)return 0;
if(*(S->top-1)!='{')return 0;
if(*(S->top-1)=='{')--S->top;break;
default:;
}
}while(Bracket!='\n');
if(S->top==S->base)
return 1;
else return 0;
}
void main()
{sqStack *S;
S=(sqStack *)malloc(sizeof(sqStack));
int idea=BracketInspect(S);
printf("%d",idea);
}
回车键(换行符)结束,亲测有效,换行符结束标识符
|