Alpha and Beta

Time Limit:1000MS  Memory Limit:65536K
Total Submit:491 Accepted:62

Description

Alpha and Beta are best friends and make company with each other all the time. 
There is a time when a game called “make pairs” gains much popularity. Alpha and Beta are very fond of it and like to invite you to play with them. 
Given a string, which is simply composed of either A or B, they want to know how many AB pairs can Alpha and Beta find in that string. Can you help them? 
A pair is legal if and only if A appears at first, and whether B is near to A is not required. In other words, B makes pair with A which is nearest before B, and they both can be used only once.

Input

There are a series of strings. The length of each string is less than 1000.

Output

For each case, if there is none legal pair that they can find, print -1. Otherwise, print the number of them. 
Please note the output format.

Sample Input

BA
AABB
BAB

Sample Output

Case #1: -1
Case #2: 2
Case #3: 1

题意:给定一个只含有A和B的字符串,问可以配对多少组A...B,若某A和某B配对以后则不可以再和别的B配对。

解法:因为要求A在B的前面,所以我们只需从头遍历一遍,找几个变量N记录A出现的次数,每出现一次A就让N自增一次,当出现B的时候,就判断一下前面有没有多余的A剩下,如果有那么消耗一个A,让N自减一次,然后答案ANS+1,如果没有A剩下了那么很遗憾,这个B就不能配对了。

AC代码:

//************************************************************************//
//*Author : Handsome How                                                 *//
//************************************************************************//
//#pragma comment(linker, "/STA    CK:1024000000,1024000000")
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
//----------------------------------------------------------
int a;
int main()
{char s[2000];int kase = 0;while(scanf("%s",s)!=EOF){a=0;int ans = 0;int len = strlen(s);for(int i=0;i<len;i++){if(s[i]=='A')a++;else if(a>0){ans++;a--;}}if(ans==0)ans=-1;printf("Case #%d: ",++kase);printf("%d\n",ans);}return 0;
}

Alpha and Beta相关推荐

  1. 金融量化alpha和beta值的意义

    金融量化alpha和beta值的意义 添加链接描述 posted on 2019-02-19 21:28 luoganttcc 阅读(...) 评论(...) 编辑 收藏

  2. 1.4 测试各阶段(单元、集成、系统 、Alpha、Beta、验收)

    单元测试: 单元测试是对软件基本组成单元(软件设计的最小单位)进行正确性检验的测试工作,如函数.过程(function,procedure)或一个类的方法(method).单元测试是一个方法层面上的测 ...

  3. 理解statsmodels中OLS对应基金alpha、beta、R-squared

    概解statsmodels <理解patsy & Design Matrices> To fit most of the models covered by statsmodels ...

  4. [转] alpha、beta、rc各版本区别

    转自:   alpha.beta.rc各版本区别 | 运维生存时间 很多软件在正式发布前都会发布一些预览版或者测试版,一般都叫"beta版"或者 "rc版",特 ...

  5. 量化交易alpha、beta、shape等基本概念梳理

    1.期货型基金(CTA)的 Alpha 和 Beta 是指什么? 1980S                                  1990S:                       ...

  6. 功能测试的类型之Alpha和Beta测试

    功能测试的类型 有六种不同类型的功能测试.每个都有不同的用途,但同时,它们都是相互关联的.那是因为它们都相互依赖:例如,如果不先运行冒烟测试,就无法直接进入alpha测试.同时,冒烟测试本身不会捕获与 ...

  7. Alpha、Beta、RC、GA、RTW版本

    目录 Pre-alpha Alpha Beta RC 版本 GA 版本 RTW 版本 Pre-alpha 有时候软件会在Alpha或Beta版本前先发布Pre-alpha版本. 一般而言相对于Alph ...

  8. 软件版本alpha、beta、gamma等

    软件版本alpha.beta.gamma等 alpha 内测版,指开发团队内部测试的版本或者有限用户体验测试版本 beta 是指公测,即针对所有用户公开的测试版本.主要是看用户对软件外观,使用方便等的 ...

  9. 软件版本—— Alpha、Beta、RC版本的区别

    传统软件工程上来说,对成形软件的测试有着三个阶段:alpha.beta 和gamma,用来标识测试的阶段与范围.alpha 指的是内测,即现在说的 CB,即开发团队内部测试的版本或者有限用户的体验测试 ...

  10. 开源软件和商业软件版本的介绍:alpha、beta、rc、GA等等

    (1)RC:(Release Candidate) Candidate是候选人的意思,用在软件上就是候选版本.Release.Candidate.就是发行候选版本.和Beta版最大的差别在于Beta阶 ...

最新文章

  1. 机器学习中的偏差和方差是什么?
  2. 迁移学习——Domain Adaptation
  3. c# 4.0(vs2010)新特性一览
  4. mysql 如何查看constraint定义的的所有约束_MySQL:如何查看表上的所有约束?
  5. ClassNotFoundException: org.apache.catalina.loader.DevLoader 自己摸索,丰衣足食
  6. java非法字符65289_求详细点的回答 谢谢
  7. SAP Gateway service language determination
  8. 云原生ASP.NET Core程序的可监测性和可观察性
  9. android studio 2.3 instant run,android studio 2.3 instant run not working
  10. flink Sql查询异常NoResourceAvailableException: Could not acquire the minimum required resources
  11. Silverlight 简明教程(3) -- 资源、样式控制、视觉状态以及部署
  12. 在 Keras 中为循环神经网络添加自定义注意层
  13. 编译easymule 1.1.5
  14. _beginthread, _beginthreadex
  15. 遗传算法应用于XGBoost的调参过程
  16. 熊出没全集光头强的机器人_熊出没:其实光头强早就不想当伐木工了,这些细节足以说明一切...
  17. Mach-O文件, 架构包framework的合并和拆分
  18. AdxMenu真的不错!我写了个中文的使用说明如下,希望大家用得着
  19. c语言long类型转换成string,如何在C ++中将long转换为string?
  20. 癸卯年新春贺文 --孤羽江绎

热门文章

  1. 洛谷 P1074靶形数独
  2. c语言a++与++a的区别
  3. Linux出现ping不通外网、xshell解决方案
  4. MUD服务器源码下载 WheelMUD (C# .NET)
  5. Ubuntu环境QT报错:-1 error: cannot find -lGL(解决99%)
  6. Linux下的/proc目录常用命令
  7. 绿色软件:飞鸽传书使用指南
  8. 飞鸽传书2010最新版
  9. 计算机硬件故障常用检查方法,电脑硬件故障常用检查办法
  10. 怎么写好你的求职信!