//跟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
*/

UVA 12902 Reverse Polish Notation的更多相关文章

  1. [LeetCode] Evaluate Reverse Polish Notation 计算逆波兰表达式

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  2. 【leetcode】Evaluate Reverse Polish Notation

    Evaluate Reverse Polish Notation 题目描述: Evaluate the value of an arithmetic expression in Reverse Pol ...

  3. leetcode150 Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  4. 【leetcode】Evaluate Reverse Polish Notation(middle)

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  5. Leetcode Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  6. [LintCode] Evaluate Reverse Polish Notation 计算逆波兰表达式

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  7. 11. Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  8. LeetCode OJ 150. Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  9. Java for LeetCode 150 Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

随机推荐

  1. Struts2安装与简单部署实例

    打开http://struts.apache.org/网站,下载strut2 版本选择: Full Distribution: Struts2完整版 建议下载该项(此版包括以下4项): Example ...

  2. 图的深度优先遍历DFS

    图的深度优先遍历是树的前序遍历的应用,其实就是一个递归的过程,我们人为的规定一种条件,或者说一种继续遍历下去的判断条件,只要满足我们定义的这种条件,我们就遍历下去,当然,走过的节点必须记录下来,当条件 ...

  3. [Oracle] Data Guard 系列(5) - 创建逻辑备库

    在创建逻辑备库之前,必须得先创建物理备库,关于如何创建物理备库,请参考<Data Guard 系列(4) - 在不停主库的情况下创建物理备库>. 1. 在物理备库上停止日志应用服务 SYS ...

  4. ObjectOutputStream 追加写入读取错误

    摘自http://blog.csdn.net/mitkey/article/details/50274543 问题描述: 用类ObjectOutputStream向文件写读对象时,碰到一个问题:新建一 ...

  5. flappy bird游戏源代码揭秘和下载

    转:http://blog.csdn.net/touchsnow/article/details/19071961 背景: 最近火爆全球的游戏flappy bird让笔者叹为观止,于是花了一天的时间山 ...

  6. Memcached安装,操作,用C#操作

    本文来自:http://li19910722.blog.163.com/blog/static/136856822201406103313163/ 1:安装 下载Memcache:http://cod ...

  7. lua编译出liblua.so

    偶遇一个事情,需要在C里面嵌入Lua代码,这真是痛苦了我好久…. 不知道为啥lua默认编译没有生成.so 的动态链接库,需要修改Makefile生成liblua.so,我用的版本是5.2 一.先修改根 ...

  8. GTID复制报错处理:Last_Error: Error 'Can't drop database 'test'; database doesn't exist' on query

    创建GTID主从连接: mysql, master_user; 报错显示: Slave_IO_Running: Yes Slave_SQL_Running: No Last_Error: Error ...

  9. ubuntu桌面环境配置及切换

    修改ubuntu默认启动的桌面环境:Ubuntu是否启动图形化界面取决于default-display-manager的设置. vi /etc/X11/default-display-manager值 ...

  10. onvif规范的实现:成功实现ONVIF协议RTSP-Video-Stream与OnvifDeviceManager的视频对接

    有了前几篇的基础,现在可以正式开始onvif的实现工作,其中一项非常重要的部分就是视频流的对接,即能够在符合onvif标准的监控客户端软件里接收到设备端NVT发来的RTSP视频流.这里,我所用的客户端 ...