C. Letter

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/180/problem/C

Description

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.

Sample Input

PRuvetSTAaYA

Sample Output

5

HINT

题意

给你一个字符串,每次操作你可以将一个大写字母变成小写字母或者小写字母变成大写字母

然后问你最少多少次操作,可以使得这个字符串变成,左边全是大写,右边全是小写字母的形式

题解:

直接暴力枚举有多少个大写字母就好了

代码

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std; #define maxn 100005
char s[maxn];
int low[maxn],high[maxn];
int main()
{
scanf("%s",s+);
int len = strlen(s+);
for(int i=;i<=len;i++)
{
low[i]=low[i-];
high[i]=high[i-];
if(s[i]<='z'&&s[i]>='a')
low[i]++;
else
high[i]++;
}
int ans = ;
for(int i=;i<=len;i++)
{
ans = min(ans,i-high[i]+(high[len]-high[i]));
}
printf("%d\n",ans);
}

Codeforces Round #116 (Div. 2, ACM-ICPC Rules) C. Letter 暴力的更多相关文章

  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 #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

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

  9. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) Letter(DP 枚举)

    Letter time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

随机推荐

  1. Ant编译和部署java web项目

    1.在myeclipse中创建javaWeb项目AntDemo 2.将build.xml放到AntDemo根目录下 3.修改build.xml中的Project name,工程目录名,工程名,还有to ...

  2. POJ 1083 Moving Tables

    题意:一个建筑物里有400个房间,房间都在一层里,在一个走廊的两侧,如图,现在要搬n张桌子,告诉你每张桌子是从哪个屋搬到哪个屋,搬桌子的线路之间不可以有重叠,问最少搬几次. 解法:贪心.一开始觉得只要 ...

  3. [Everyday Mathematics]20150129

    计算下列积分 $$\bex \int_a^b (x-a)^2(b-x)^3\rd x. \eex$$

  4. 分布式发布订阅消息系统 Kafka 架构设计

    我们为什么要搭建该系统 Kafka是一个分布式.分区的.多副本的.多订阅者的“提交”日志系统. 我们构建这个系统是因为我们认为,一个实现完好的操作日志系统是一个最基本的基础设施,它可以替代一些系统来作 ...

  5. javascript 面向对象整理

    整理一下js面向对象中的封装和继承. 1.封装 js中封装有很多种实现方式,这里列出常用的几种. 1.1 原始模式生成对象 直接将我们的成员写入对象中,用函数返回. 缺点:很难看出是一个模式出来的实例 ...

  6. Cadence原理图与Allegro交互

    1:激活orCAD与Allegro的交互程序 打开原理图,Options->Preference在Miscellaneous里勾选 2:打开用到的工程 原理图,还有Allegro PCB Des ...

  7. 【C# C++】C#中调用msvcr100.dll中的_beginthreadex函数

    msvcr100.dll是VS2010的C运行时库DLL, _beginthreadex开启子线程的函数就在这个DLL里面实现 unsigned long _beginthreadex(    voi ...

  8. [GRYZ2015]Graph

    题目描述 给出 N 个点,M 条边的有向图,对于每个点 v,求 A(v) 表示从点 v 出发,能到达的编号最大的点. 输入格式 第 1 行,2 个整数 N,M. 接下来 M 行,每行 2 个整数 Ui ...

  9. Python相关书籍推荐

    Python基础教程(第2版 修订版) 作      者 [挪] Magnus Lie Hetland 著:司维,曾军崴,谭颖华 译 出 版 社 人民邮电出版社 出版时间 2014-06-01 版   ...

  10. Tkinter教程之Radiobutton篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811308 #Tkinter教程之Radiobutton篇#Radiobutton为单选按钮, ...