博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Happiness
阅读量:6537 次
发布时间:2019-06-24

本文共 1746 字,大约阅读时间需要 5 分钟。

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 
#include
#include
#include
#include
using namespace std;char str[1000010];int main (){ int t,i,k=0; scanf("%d",&t); while(t--) { k++; printf("Case #%d:\n",k); int sum=0; scanf("%s",str); for(i=0;str[i]!='\0';i++) { if(str[i]=='A' && str[i+1]=='B') { sum++; } } printf("%d\n",sum); } return 0;}

转载于:https://www.cnblogs.com/lanaiwanqi/p/10445710.html

你可能感兴趣的文章
Cannot return from outside a function or method
查看>>
完整卸载 kUbuntu-desktop from Ubuntu 14.04 LTS系统 ubuntu14.04 LTS 64Bit
查看>>
activeMQ:java消息机制初试(一)
查看>>
/boot/grub/grub.conf 内容诠释
查看>>
Python——特殊属性与方法
查看>>
laravel基础课程---1、laravel安装及基础介绍(laravel如何安装)
查看>>
php实现表示数值的字符串(is_numeric($s))
查看>>
将Apache service加入到开机启动中
查看>>
0基础学C语言:C语言视频教程免费分享!
查看>>
Python Module_os_操作系统
查看>>
用 Flask 来写个轻博客 (19) — 以 Bcrypt 密文存储账户信息与实现用户登陆表单
查看>>
用 Flask 来写个轻博客 (19) — 以 Bcrypt 密文存储账户信息与实现用户登陆表单
查看>>
tomcat的编码方式
查看>>
scala数据库工具类
查看>>
解决 Jsp_Servlet 编码乱码问题
查看>>
PHP7扩展开发之Hello World
查看>>
Linux基础
查看>>
第三章 请求与响应
查看>>
垃圾收集器与内存分配策略
查看>>
看视频学Bootstrap—在微软虚拟学院学习Bootstrap
查看>>