#include <iostream>
#include <string>
using namespace std;
void push(char a);
void pop();
void main()
{
char one[100];
char stack[50];
char*sp,*buffer;
buffer=stack;
sp=buffer;
cin>>one;
do
{
int n=0;
switch(one[n]){
case'(': push(one[n]);break;
case'[': {
if(one[n]='(')
cout<<"@@@@@"<<endl;break;
if(one[n]='[')
cout<<"@@@@@"<<endl;break;
push(one[n]);break;
}
case'{':
{
if(one[n]='(')
cout<<"@@@@@"<<endl;break;
if(one[n]='[')
cout<<"@@@@@"<<endl;break;
if(one[n]='{')
cout<<"@@@@@"<<endl;break;
push(one[n]);break;
}
case')':
if(stack[n-1]='(')
pop();
cout<<"@@@@@";
break;
case']':
if(stack[n-1]='[')
pop();
cout<<"@@@@@";
break;
case'}':
if(stack[n-1]='{')
pop();
cout<<"@@@@@";
break;
default: n++;}
}while(1);
if(buffer)
{
delete buffer;
cout<<"栈空间已释放";
}
void push(char a)
{
if(sp>buffer+50)
{
cout<<"栈空间不够,栈溢出!"<<endl;
exit(1);
}else
*sp++=a;
}
void pop()
{
sp--;
if(sp<buffer)
{
cout<<"已越过栈底!"<<endl;
exit(1);
}
}
BIG阳
相关分类