Letter
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.

Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.

To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.

Input

The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.

Output

Print a single number — the least number of actions needed to make the message fancy.

Examples
input
PRuvetSTAaYA
output
5
input
OYPROSTIYAOPECHATALSYAPRIVETSTASYA
output
0
input
helloworld
output
0

【题意】给你一个字符串,每一次操作可以将大写字母改成小写,反之亦然。问经过最少的操作数,使得此串的大写字母全部都在小写字母的左边。

【分析】感觉跟DP没啥关系,直接枚举...

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
using namespace std;
typedef long long LL;
const int N = 1e5+;
const int mod = 1e9+;
int n,a,b,k;
int dp[N],sum[N];
char str[N];
int main(){
scanf("%s",str);
int len=strlen(str);
for(int i=len-;i>=;i--){
sum[i]=sum[i+]+(str[i]>='a'?:);
}
int s=,ans=sum[];
for(int i=;i<len;i++){
s+=(str[i]>='a'?:);
ans=min(ans,sum[i+]+s);
}
printf("%d\n",ans);
return ;
}

Codeforces Round #116 (Div. 2, ACM-ICPC Rules) Letter(DP 枚举)的更多相关文章

  1. codeforces水题100道 第十八题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/509/A题意:f[i][1]=f[1][i]=1,f[i][j]=f[i-1][j]+f[i][j ...

  2. Codeforces Round #289 (Div. 2, ACM ICPC Rules) E. Pretty Song 算贡献+前缀和

    E. Pretty Song time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table【递推】

    A. Maximum in Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles

    题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...

  5. 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table

    题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...

  6. Codeforces Round #116 (Div. 2, ACM-ICPC Rules)

    Codeforces Round #116 (Div. 2, ACM-ICPC Rules) 代码 Codeforces Round #116 (Div. 2, ACM-ICPC Rules) A. ...

  7. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  8. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  9. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  10. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) C. Letter 暴力

    C. Letter Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/180/problem/C D ...

随机推荐

  1. AWK文本分析工具-常用场景(持续更新中)

    AWK help document:http://www.gnu.org/software/gawk/manual/gawk.html 问题 awk命令 备注 对请求IP统计分组排序?     显示列 ...

  2. Item 12 考虑实现Comparable接口

    1.Comparable接口,用来做什么. 2.判定类实现的Comparable接口是否正确的方法. 3.不要扩展一个已经实现了Comparable接口的类来增加用于比较的值组件.     1.Com ...

  3. HDU 1312 Red and Black (深搜)

    题目链接 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore ...

  4. metasploit后门维持技术

    在meterpreter中执行:run metsvc -A 如此以后便会自动在服务器当中多生成一个meterpreter的服务,并且是开机自动启动.所以二次如果要利用直接: use exploit/m ...

  5. 多表数据转化器MTDC

    需求 根据配置文件的映射规则,将一种模型和数据映射成另外一种模型和数据.如图: 其中,a1,b1,c1,d1为表主键,关系:A.a1=B.b1=C.c2=D.d1 解决思路 解析模型配置文件,将每个转 ...

  6. 【转】cve-2013-2094 perf_event_open 漏洞分析

    cve-2013-2094是于2013年4月前后发现的linux kernel本地漏洞,该漏洞影响3.8.9之前开启了PERF_EVENT的linux系统.利用该漏洞,通过perf_event_ope ...

  7. IDEA 内存设置

    -server -Xms2g -Xmx2g -XX:NewRatio=3 -Xss16m -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled - ...

  8. Linux系统编程——进程间通信(System V IPC 对象)

    基本查看命令 ipcs  -m查看共享内存        ipcs -s查看信号量        ipcs -q查看消息队列 ipcrm  -m  id 删除共享内存   -M+key值 ipcrm ...

  9. 高性能网络编程(1)—accept建立连接‍(待研究)

    阿里云博客上一篇感觉还不错的文章,待研究,原文链接如下: http://blog.aliyun.com/673?spm=5176.7114037.1996646101.3.oBgpZQ&pos ...

  10. jstack 命令学习笔记

    大部分内容转载自:Java命令学习系列(二)--Jstack jstack - 查看堆栈信息 jstack ( Stack Trace for java ) 命令主要作用就是为了查看堆栈信息.它可以用 ...