#include<stdio.h>
#define maxsize 100
typedef struct
{
char optr[maxsize];
int top;
}OPTR;
void initstack(OPTR& s)
{
s.top = -1;
}
bool push(OPTR& s, char c)
{
if (s.top == maxsize - 1)
return false;
s.top += 1;
s.optr[s.top] = c;
return true;
}
bool pop(OPTR& s, char& c1)
{
if (s.top == -1)
return false;
c1 = s.optr[s.top];
s.top -= 1;
return true;
}
bool gettop(OPTR s, char& c2)
{
if (s.top == -1)
return false;
c2 = s.optr[s.top];
return true;
}
int main()
{
OPTR s;
char a,b;
while (a = getchar())
{
switch (a)
{
case '(':
case '[':
case '{':
push(s, a);
break;
case ')':
gettop(s, b);
if (b != '(' ){
printf("与栈顶元素不匹配");
return 0;
}
break;
case ']':
gettop(s, b);
if (b != '[') {
printf("与栈顶元素不匹配");
return 0;
}
break;
case '}':
gettop(s, b);
if (b != '{') {
printf("与栈顶元素不匹配");
return 0;
}
break;
}
}
}