Happiness

<center style="color&#58;rgba&#40;0&#44;0&#44;0&#44;&#46;87&#41;&#59;font&#45;family&#58;Lato&#44; &#39;Helvetica Neue&#39;&#44; Arial&#44; Helvetica&#44; sans&#45;serif&#59;font&#45;size&#58;14px&#59;">

1575: Happiness

时间限制: 1 Sec   内存限制: 1280 MB
</center>

题目描述

       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. 

输入

       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. 

输出

     For each test case:

    The first line output “Case #k:", k indicates the case number.    

    The second line output the answer. 

样例输入

1
ABABBBA

样例输出

Case #1:
2

解题思路

水题。

#include <stdio.h>
#include <string.h>
char str[1000010];
int main()
{
    int t, count, len;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++)
    {
        count = 0;
        scanf("%s", str);
        len = strlen(str);
        for (int j = 1; j < len; j++)
        {
            if (str[j - 1] == 'A' && str[j] == 'B')
                count++;
        }
        printf("Case #%d:\n%d\n",i, count);
    }
    return 0;
}
全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
饿魔:看到在线简历了吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务