zoukankan      html  css  js  c++  java
  • 8.1.7 愚人节的礼物

    愚人节的礼物

    Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 32 Accepted Submission(s): 30

    Problem Description
    四月一日快到了,Vayko想了个愚人的好办法——送礼物。嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物。盒子里面可以再放零个或者多个盒子。假设放礼物的盒子里不再放其他盒子。

    用()表示一个盒子,B表示礼物,Vayko想让你帮她算出愚人指数,即最少需要拆多少个盒子才能拿到礼物。
     

    Input
    本题目包含多组测试,请处理到文件结束。
    每组测试包含一个长度不大于1000,只包含'(',')'和'B'三种字符的字符串,代表Vayko设计的礼物透视图。
    你可以假设,每个透视图画的都是合法的。
     

    Output
    对于每组测试,请在一行里面输出愚人指数。
     

    Sample Input
    ((((B)()))())
    (B)
     

    Sample Output
    4
    1
     

    Author
    Kiki
     

    Source
    2008杭电集训队选拔赛——热身赛

    for语句啊,左括号减去右括号

     1 #include <cmath>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <string>
     6 #include <cstdlib>
     7 using namespace std;
     8 
     9 const int maxn=1100;
    10 char s[maxn];
    11 int cnt,l;
    12 
    13 void close()
    14 {
    15 exit(0);
    16 }
    17 
    18 
    19 void init()
    20 {
    21     while (fgets(s,2100,stdin)!=NULL)
    22     {
    23         cnt=0;
    24         l=strlen(s);
    25         for (int i=0;i<l;i++)
    26         {
    27             if (s[i]=='B')
    28             {
    29                 printf("%d
    ",cnt);
    30             }
    31             if (s[i]=='(')
    32                 cnt++;
    33             if (s[i]==')')
    34                 cnt--;
    35         }
    36     }
    37 }
    38 
    39 int main ()
    40 {
    41     init();
    42     close();
    43     return 0;
    44 }
  • 相关阅读:
    函数式语言(老师作业)
    session/cookie
    Linux根目录下各个目录的功能介绍
    Navicat12安装文件和破解补丁
    正则表达式验证示例
    RequestDispatcher接口示例
    hello2部分源码解析
    Introduction of Servlet Filter
    关于hello1中的web.xml解析
    Annotation解释
  • 原文地址:https://www.cnblogs.com/cssystem/p/3212499.html
Copyright © 2011-2022 走看看