zoukankan      html  css  js  c++  java
  • 华中农业大学第五届程序设计大赛网络同步赛-L

    L.Happiness

    Chicken brother is very happy today, because he attained N pieces of biscuits whose tastes are A or B. These biscuits are put into a box. Now, he can only take out one piece of biscuit from the box one time. As we all know, chicken brother is a creative man. He wants to put an A biscuit and a B biscuit together and eat them. If he take out an A biscuit from the box and then he take out a B biscuit continuously, he can put them together and eat happily. Chicken brother’s happiness will plus one when he eat A and B biscuit together one time. Now, you are given the arrangement of the biscuits in the box(from top to bottom) ,please output the happiness of Chicken Brother when he take out all biscuit from the box.

    Input Description

    The first line is an integer indicates the number of test cases. In each case, there is one line includes a string consists of characters ‘A’ and ‘B’. The length of string is not more than 1000000.

    Output Description

    For each test case: The first line output “Case #k:", k indicates the case number. The second line output the answer.

    Sample Input

    1

    ABABBBA

    Sample Output

    Case #1:

    2

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     int T;
    11     string str;
    12     cin>>T;
    13     for(int kase = 1; kase <= T; kase++)
    14     {
    15         cin>>str;
    16         int len = str.length(), ans = 0;
    17         for(int i = 0; i < len-1; i++)
    18             if(str[i] == 'A' && str[i+1] == 'B')
    19                   ans++;
    20         cout<<"Case #"<<kase<<":"<<endl;
    21         cout<<ans<<endl;
    22     }
    23 
    24     return 0;
    25 }
  • 相关阅读:
    布局常见问题之css实现多行文本溢出显示省略号(…)全攻略
    网站常用js代码搜集
    js--事件对象的理解5-
    js--事件对象的理解4
    关于.NET邮件的收发问题总结
    .net 与 javascript脚本的几种交互方法
    word在线编辑生成图片(包含截图与合并)
    使用GDI+轻松创建缩略图
    C#反射之基础应用
    C# Winform 实现自定义半透明loading加载遮罩层
  • 原文地址:https://www.cnblogs.com/Penn000/p/6756257.html
Copyright © 2011-2022 走看看