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. Flow Problem
  2. ElasticSearch评分分析 explian 解释和一些查询理解
  3. android 保存文件_Android 数据库操作框架LitePal使用介绍(一)
  4. 五、规则组织的衍生组织——纬山形组织数学模型的建立
  5. linux df和du常用命令
  6. java数字分割的下划线_Java-数值中使用下划线进行分隔
  7. zoj 1372
  8. JAVA 使用Dom4j 解析XML
  9. PDFcrack暴力破解pdf密码
  10. java apdu读取社保卡_读取社保卡信息 - osc_qzrqhs9y的个人空间 - OSCHINA - 中文开源技术交流社区...
  11. Spider_Man_5.2 の Mongodb_使用
  12. 全开源即时通讯(IM)系统-仿微信
  13. 下载配置安装MySql---超详细教程
  14. 相机镜头上的所有字母,首字母缩写和数字代表什么?
  15. 将自己的SSH密钥对导入YubiKey 5的PIV和智能卡模块,配合Putty和XShell使用
  16. 石英晶体(Crystal)振荡电路
  17. 100兆每秒传输不是12.5MB,别误人子弟了
  18. Apache Commons Lang3 DateUtils用法
  19. 谁有cmmi v2.0中文版本的下载地址,分享一下,谢谢
  20. WCDMA与cdma2000网络结构比较

热门文章

  1. Python软件目录结构规范
  2. 【Java】Java 开发手册以及规范
  3. 读冯唐先生的《素女经》
  4. ESP8266开发板
  5. 中国锂电池隔膜行业发展模式深度分析及十四五战略研究报告2021-2027年版
  6. vue项目中集成腾讯TIM即时通讯(附源码)
  7. 自己动手写一个strlen()函数
  8. 植物大战僵尸:分析植物的攻击速度
  9. Oracle企业管理器(OEM)常见问题解答
  10. 【技术案例】智能语音CAEDemo程序