zoukankan      html  css  js  c++  java
  • 括弧匹配检验(check)

     1 /*题目:括弧匹配检验
     2 检验给定表达式中括弧是否正确匹配 (两种括弧“( ) ”“[]" ,正确输出OK,错误则输出wrong。 
     3 2016年8月8日07:24:58
     4 作者:冰樱梦 
     5 
     6 */
     7 # include <iostream>
     8 # include <cstring>
     9 # include <cstdio>
    10 using namespace std;
    11 char s[300];
    12 int top=0, i;
    13 bool panduan(char s[300])
    14 {
    15     for(i=0;i<strlen(s);i++)
    16     {
    17         if(s[i]=='('||s[i]=='[') top++;      //此处有逻辑或 “|| ” 
    18         if(s[i]==')'||s[i]==']')             
    19         {
    20             if(top>0) top--;
    21             else return 0;
    22         }
    23     }
    24     if(top != 0) return 0;
    25     else return 1;
    26 }
    27 int main()
    28 {
    29     scanf("%s",s);
    30     if(panduan(s)) cout<<"OK";
    31     else cout<<"Wrong";
    32     return 0;
    33 }
  • 相关阅读:
    Codeforces Round #249 (Div. 2) D. Special Grid 枚举
    图论二
    C语言中的atan和atan2(转)
    BestCoder Round #79 (div.2)
    数学
    LCA
    二分图
    动态规划
    线段树
    树状数组
  • 原文地址:https://www.cnblogs.com/blym/p/5747918.html
Copyright © 2011-2022 走看看