<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;
}