括号匹配检验 c++
2015-04-13 13:01
260 查看
#include<iostream> #include<stack> using namespace std; void main(){ int i,invalid = 0; char a[50]; char *s=a; stack<char> st; st.empty(); cin >> a; while(*s!='\0') { if(*s == '['|| *s == '(') st.push(*s); else { if(*s == ']') { if(st.top() != '[') { invalid = 1; break; } else st.pop(); } if(*s == ')') { if(st.top()!='(') { invalid = 1; break; } else st.pop(); } } s++; } if(!st.empty()) invalid = 1; if(invalid) cout<<"invalid!"<<endl; else cout<<"ok!"<<endl; cin>>i; }
相关文章推荐
- 栈的应用--括号匹配的检验(C++)
- 数据结构题典021:栈的应用——括号匹配的检验(C++)
- 算法学习 - 括号匹配(栈实现)C++
- 用栈实现括号匹配的检验
- 括号的匹配检验
- C++括号匹配程序
- 数据结构课程设计:括号匹配问题(实现检验匹配并输出不匹配的位置)
- 括号匹配的检验
- 括号匹配的检验
- C语言数据结构-桟——括号的匹配检验
- C++ Stack Application - (Parenthesis Matching) 堆栈应用之"括号匹配"
- 用栈实现括号匹配的检验
- C++之桟的应用---括号匹配
- 数据结构 P49 栈的应用举例-括号匹配的检验
- 使用vim编写c++对于输入输出流<<和<>括号匹配冲突的解决方法
- [C++]连续最长括号匹配问题
- 栈的应用:括号匹配检验
- 括号匹配的检验
- C++ 字符串删除匹配括号及括号里的内容
- 递归应用之括号匹配检验