括弧匹配检验

团队QQ:466373640
个人博客:www.doubleq.win
c++/noi/信息学奥数博客:http://www.cnblogs.com/zwfymqz
#include<iostream> #include<cstring> #include<cstdio> using namespace std; char a[10001];//( ) char b[10001]; char c[10001]; int main() { int top=0; int top_b=0; gets(c); int l=strlen(c); for(int i=0;i<=l;i++) { if(c[i]=='(') { top++; a[top]='('; } else if(c[i]==')') { if(a[top-1]=='(') top=top-2; } else if(c[i]=='[') { top++; a[top]='['; } else if(c[i]==']') { if(a[top-1]=='[') //top--; top=top-2; } } if(top==0) { cout<<"Yes"; } else cout<<"Wrong"; return 0; }

 

个人QQ:757394026
团队QQ:466373640
个人博客:www.doubleq.win
c++/noi/信息学奥数博客:http://www.cnblogs.com/zwfymqz

 

posted @ 2017-02-27 16:20  自为风月马前卒  阅读(223)  评论(0编辑  收藏  举报

Contact with me