• 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 }
  • 相关阅读:
    二维码生成器
    uniapp 上下左右手势滑动时的事件
    uniapp 类似钉钉的消息时间段显示
    css 币种与价格的底部对齐
    css 设置父元素透明度不影响子元素透明度
    js match方法截取某个字符串前面的内容
    下载电脑系统,服务等...
    uniapp 实现点击、滑动切换tab导航内容
    vue 实现分类渲染数据
    jquery 实现在事件完成后才能再次点击执行
  • 原文地址:https://www.cnblogs.com/cssystem/p/3212499.html
Copyright © 2020-2023  润新知