当前位置: 首页 > news >正文

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:\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

相关文章:

  • 解决Server Application Unavailable问题
  • 用TensorFlow实现文本分析模型,做个聊天机器人
  • 转载:什么是高级C++?
  • AV Foundation 的剖析 1.0
  • 红旗Linux+Oracle10g
  • vue30-单一事件管理组件通信: vuex
  • C#和ASP.Net面试题目集锦
  • java 基础概念 -- 数组与内存控制
  • (求助)用傲游上csdn博客时标签栏和网址栏一直显示袁萌 的头像
  • mysql wait_timeout和interactive_timeout总结
  • scrapy-splash抓取动态数据例子十
  • (读书笔记)Javascript高级程序设计---ECMAScript基础
  • 使用隐含Trace参数诊断Oracle Data Pump(expdp)故障
  • 当Java代码遇上抽象、重载加重写,一切都不美好了
  • 毕业(247)
  • 网络传输文件的问题
  • [iOS]Core Data浅析一 -- 启用Core Data
  • 4. 路由到控制器 - Laravel从零开始教程
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • django开发-定时任务的使用
  • HTTP那些事
  • js学习笔记
  • laravel 用artisan创建自己的模板
  • Linux快速复制或删除大量小文件
  • Vue.js-Day01
  • 翻译--Thinking in React
  • 聚类分析——Kmeans
  • 一个普通的 5 年iOS开发者的自我总结,以及5年开发经历和感想!
  • 一个完整Java Web项目背后的密码
  • 中文输入法与React文本输入框的问题与解决方案
  • const的用法,特别是用在函数前面与后面的区别
  • "无招胜有招"nbsp;史上最全的互…
  • #include到底该写在哪
  • $.extend({},旧的,新的);合并对象,后面的覆盖前面的
  • (env: Windows,mp,1.06.2308310; lib: 3.2.4) uniapp微信小程序
  • (二)JAVA使用POI操作excel
  • (二)基于wpr_simulation 的Ros机器人运动控制,gazebo仿真
  • (入门自用)--C++--抽象类--多态原理--虚表--1020
  • (详细版)Vary: Scaling up the Vision Vocabulary for Large Vision-Language Models
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (转)为C# Windows服务添加安装程序
  • ****Linux下Mysql的安装和配置
  • .net core 实现redis分片_基于 Redis 的分布式任务调度框架 earth-frost
  • .NET Micro Framework初体验
  • ::前边啥也没有
  • [2016.7 Day.4] T1 游戏 [正解:二分图 偏解:奇葩贪心+模拟?(不知如何称呼不过居然比std还快)]
  • [Angular] 笔记 8:list/detail 页面以及@Input
  • [Django ]Django 的数据库操作
  • [EFI]ASUS EX-B365M-V5 Gold G5400 CPU电脑 Hackintosh 黑苹果引导文件
  • [Godot] 3D拾取
  • [GPT]Andrej Karpathy微软Build大会GPT演讲(上)--GPT如何训练
  • [IE编程] 如何在IE8 下调试BHO控件/工具栏(调试Tab进程)
  • [JS入门到进阶] 哎,被vite小坑了一波,大家记得配置build.cssTarget为‘chrome61‘
  • [Machine Learning][Part 7]神经网络的基本组成结构
  • [ndss 2023]确保联邦敏感主题分类免受中毒攻击