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. wcf 服务创建,配置,测试

    一.WCF创建: 常规的创建WCF服务是通过SOAP传输的,很多网站开发人员想放弃使用XML而使用JSON,这个时候可以参照:http://www.cnblogs.com/zhili/p/WCFRes ...

  2. tomcat优化总结【持续更新】

    配置优化 <Connector port=" maxThreads=" URIEncoding="UTF-8" maxKeepAliveRequests= ...

  3. vue清空input file

    input file是只读的,给form一个id,用form.reset()干掉里面input的值 document.getElementById("uploadForm")&am ...

  4. window对象的方法和属性汇总

    window对象有以下方法: open close alert confirm prompt setTimeout clearTimeout setInterval clearInterval mov ...

  5. Python 模块搜索路径 -- (转)

    最近在看<Python源码剖析>,对Python内部运行机制比以前了解的更深入了,感觉自己有机会也可以做个小型的动态脚本语言了,呵呵,当然是吹牛了.目的当然不是创造一个动态语言,目的只有一 ...

  6. 【tomcat】手动部署动态JavaWeb项目到tomcat

    1.通过修改server.xml进行配置 1.查看项目的目录结构: tomcat运行时加载WebConmtent目录

  7. CTSC/APIO2018 帝都一周游

    day0 报道 上午早早就起来了,两点才到酒店,然后去简单试了试机子. 不得不说今年八十中的伙食变得瓜皮了啊,去年还是大叠的5元卷,今年变成了单张的*餐卷.不知道食堂吝啬什么,面条米饭都只有一点点,还 ...

  8. 【Git/GitHub学习笔记】基本操作——创建仓库,本地、远程同步等

    近日想分享一些文件,但是用度盘又太麻烦了(速度也很恶心).所以突发奇想去研究了下GitHub的仓库,这篇文章也就是一个最最最基础的基本操作.基本实现了可以在GitHub上存储文本信息与代码. 由于我的 ...

  9. Linux内核模块编程可以使用的内核组件

    2.2.2 在阅读<深入Linux内核架构与底层原理> 作者:刘京洋 韩方,发现一些错误,有些自己的理解,特以此记录 1.工作队列(workqueue) 队列是一种可以先进先出的数据结构, ...

  10. java===java基础学习(10)---对象构造

    重载 如果多个方法有相同的名字,不同的参数,便产生了重载.编译器必须挑选出具体执行哪个方法,他通过用各个方法给出的参数类I型那个与特定方法调用所使用的值类型进行匹配来挑选出相应的方法.如果编译器找不到 ...