//跟wyr学的
//其实是贪心
//题解稍后补上
 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#define LL long long const int MAXN=;
const int MAXM=;
const int INF=; using namespace std; int T;
char s[]; int solve(){
int len=strlen(s);
int MIN=INF;
int now=;
int flag=;
for (int i=;i<len;i++){
if (s[i]=='a')
now++;
else
now--;
if (now==MIN) flag=;
if (now<MIN){
MIN=now;
flag=;
}
}
if (MIN>=) return now-;
if (MIN==now) return +abs(now);
return +now-MIN*-flag;
} int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
scanf("%s",s);
int ans=solve();
if (s[]=='+' && s[]=='a' && s[]=='a'){
s[]='a';
s[]='a';
s[]='+';
ans=min(ans,solve()+);
}
printf("Case %d: %d\n",cas,ans);
}
return ;
}
/*
4
a
a+a
+aa
aa++++a
*/

最新文章

  1. springMVC初探--环境搭建和第一个HelloWorld简单项目
  2. android上下文菜单
  3. reference
  4. 学习ExtJs教程初级
  5. 基于注解配置的Spring MVC 简单的HelloWorld实例应用
  6. python中property干什么用的?
  7. 中国首个 SaaS 模式的云告警平台 iOS 版 APP 上线
  8. State 状态模式
  9. php常用mysql函数
  10. python 多线程一(lock)
  11. BaseServer的介绍
  12. linkin大话面向对象--初始化块
  13. BZOJ 4455
  14. request鉴权的处理和判断
  15. iqiyi__youku__cookie_设置
  16. linux 压缩和解压命令
  17. 关于Unity中的光照(四)
  18. python-django开发学习笔记一
  19. network出错
  20. malloc 函数本身并不识别要申请的内存是什么类型

热门文章

  1. SQL Server 2008空间数据应用系列四:基础空间对象与函数应用
  2. H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式
  3. 使用 ServKit(PHPnow) 搭建 PHP 环境[图]
  4. 《Qt编程的艺术》——5.1 手动布局
  5. dom4j解析XML的CURD操作
  6. Windows下安装Memcache
  7. .net web api 一
  8. Android开发_关于点击事件
  9. WinForm设置控件焦点(转)
  10. javascript 高级程序设计学习笔记(面向对象的程序设计) 2