/*#include<iostream.h> class stack { private: int count,maxsize; char *elem; public: stack(int size) { maxsize=size; count=0; elem=new char[maxsize]; } void input(int size,char *s) { cout<<"请输入一个长度不大于"<<size<<"的式子"<<endl; cin>>s; } void push(char &ch1) { if(count==maxsize) cout<<"栈已满,无法入栈"<<endl; else { elem[count++]=ch1; } } void pop(char &ch2) { if(count==0) cout<<"栈中已无元素"<<endl; else { ch2=elem[count-1]; count--; } } bool empty() { return count==0; } }; void main() { int size; char *s; char temp; char ch1='{',ch3='(',ch2='[',ch4=')',ch5=']',ch6='}'; cout<<"请输入一个式子的最大长度"<<endl; cin>>size; stack stack1(size); s=new char[size]; stack1.input(size,s); for(int i=0;i<size;i++) { if(s[i]==ch1) { stack1.push(ch6); } else if(s[i]==ch2) { stack1.push(ch5); } else if(s[i]==ch3) { stack1.push(ch4); } else if(s[i]==ch4||s[i]==ch5||s[i]==ch6) { stack1.pop(temp); if(s[i]!=temp) { cout<<"符号匹配出错"<<endl; break; } } } if(!stack1.empty()) cout<<"匹配出错"<<endl; }