zoukankan      html  css  js  c++  java
  • Happiness

    题目来源:2017华中农大网络赛 L

    L.Happiness

    Chicken brother is very happy today, because he attained N pieces of biscuits whosetastes 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 toput an A biscuit and a B biscuit together and eat them. If he take out an A biscuit from thebox 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 tobottom) ,please output the happiness of Chicken Brother when he take out all biscuit fromthe 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

    题意概括

    给一个字符串,找出其中存在多少个AB这样的子串。

    解题思路

    搜索一遍就好了。

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <ctype.h>
    #include <algorithm>
    
    using namespace std;
    
    char str[1000010];
    int main ()
    {
        int t,i,k=0;
        scanf("%d",&t);
        while(t--)
        {
            k++;
            printf("Case #%d:
    ",k);
            int sum=0;
            scanf("%s",str);
            for(i=0;str[i]!='';i++)
            {
                if(str[i]=='A' && str[i+1]=='B')
                {
                    sum++;
                }
            }
            printf("%d
    ",sum);
        }
        return 0;
    }
    
  • 相关阅读:
    第十七节--Hystrix服务熔断
    第十六节--Hystrix之服务降级全局配置
    第十五节--Hystrix之服务降级
    第十四节--Hystrix断路器
    第十三节--OpenFeign服务接口调用
    第十二节--Ribbon
    第十一节--三个注册中心对比
    uni-app开发小说阅读器
    H5+微信朋友、朋友圈分享
    uni-app开发音乐电子书库
  • 原文地址:https://www.cnblogs.com/lanaiwanqi/p/10445710.html
Copyright © 2011-2022 走看看