您的位置:首页 > 理论基础 > 计算机网络

华中农业大学第五届程序设计大赛网络同步赛-L

2017-04-24 12:28 393 查看

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
int T;
string str;
cin>>T;
for(int kase = 1; kase <= T; kase++)
{
cin>>str;
int len = str.length(), ans = 0;
for(int i = 0; i < len-1; i++)
if(str[i] == 'A' && str[i+1] == 'B')
ans++;
cout<<"Case #"<<kase<<":"<<endl;
cout<<ans<<endl;
}

return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐