括号匹配问题 1 By yusijia May 02 2016 Updated:May 02 2016 Contents 1234567891011121314151617181920212223242526272829303132333435#include <iostream>#include <cstdio>#include <stack>#include <string>using namespace std;int main(){ stack<char> sta; printf("请输入括号序列:以#结束\n"); char a; do{ cin >> a; switch(a){ case '(' : sta.push(a);break; case ')' : if(!sta.empty()){ sta.pop(); break; } if(sta.empty()){ cout << "Wrong!" << endl; return 0; } } }while(a != '#'); if(sta.empty()) cout << "OK" << endl; else cout << "Wrong!" << endl; return 0;}