//跟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. 【转】 linux内核移植和驱动添加(三)

    原文网址:http://blog.chinaunix.net/uid-29589379-id-4708909.html 原文地址:linux内核移植和驱动添加(三) 作者:genehang 四,LED ...

  2. 理解最短路径——迪杰斯特拉(dijkstra)算法

    原址地址:http://ibupu.link/?id=29 1.       迪杰斯特拉算法简介 迪杰斯特拉(dijkstra)算法是典型的用来解决最短路径的算法,也是很多教程中的范例,由荷兰计算机科 ...

  3. javac命令详解(下)

    摘自http://blog.csdn.net/hudashi/article/details/7058999 javac命令详解(下)                             -ver ...

  4. HBase 6、用Phoenix Java api操作HBase

    开发环境准备:eclipse3.5.jdk1.7.window8.hadoop2.2.0.hbase0.98.0.2.phoenix4.3.0 1.从集群拷贝以下文件:core-site.xml.hb ...

  5. PHP - 多维数组

    多维数组指的是包含一个或多个数组的数组. PHP 能理解两.三.四或五级甚至更多级的多维数组.不过,超过三级深的数组对于大多数人难于管理. 注释:数组的维度指示您需要选择元素的索引数. 对于二维数组, ...

  6. docker 实战---使用oracle xe作为开发数据库(六)

    oracle作为oltp的大佬,非常多行业应用都会用到它.那么在开发的过程中就不可避免的要使用oracle数据库,oracle数据库的版本号有好多,当中express版本号是免费的开发版.它的主要限制 ...

  7. 模板方法模式(TemplateMethod)

    定义:模板方法模式,定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 当我们要完成在某一细节层次一致的一个过程或一系列步骤 ...

  8. 【Java基础】构造方法调用构造方法

    从一个程序开始: class dog { private String name; private String color; private int age; dog(String name) // ...

  9. 自定义的GitLab 头像无法正常显示以及URL总是指向localhost

    解决指向localhost的问题: 编辑gitlab的配置vi /etc/gitlab/gitlab.rb,修改external_url 参数值 [Mesogene@localhost ~]$ sud ...

  10. UIView的clipsTobounds属性

    这里的clip是修剪的意思,bounds是边界的意思,合起来就是:如果子视图的范围超出了父视图的边界,那么超出的部分就会被裁剪掉.该属性在实际工程中还是非常实用的,必须要了解清楚.