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);
}

最新文章

  1. Chrome Extension 检查视图(无效)处理方法
  2. 转:union和union all的区别
  3. Code First05--CodeFirst中值对象
  4. ajax提交表单
  5. Zookeeper未授权访问
  6. hydra
  7. 第二节:Maven的运行机制
  8. Web Services
  9. Java设计模式---装饰模式
  10. H5实现图片优化上传
  11. html系列教程--article audio
  12. hosts文件原理
  13. sudo 做不到的事
  14. Java 工厂模式(一)— 抽象工厂(Abstract Factory)模式
  15. Java 数据类型总结
  16. java.lang.UnsatisfiedLinkError: dlopen failed: library &quot;libsqlite.so&quot; not found
  17. 计蒜客--移除数组中的重复元素 (set)
  18. MySQL InnoDB Engine--缓冲器数据交换
  19. java设计模式(一)【六大原则】
  20. November 09th, 2017 Week 45th Thursday

热门文章

  1. 一个好用的hibernate泛型dao
  2. 本博客迁移到Github,之后停止更新
  3. [转] C#操作EXCEL,生成图表的全面应用
  4. IOS GCD
  5. Hadoop对文本文件的快速全局排序
  6. 多线程下OpenCV操作的问题
  7. CentsOS7 网络自动启动
  8. nodejs写的一个网页爬虫例子(坏链率)
  9. 瞬间从IT屌丝变大神——注释规则
  10. 常用抓包指令for wireshark or tcpdump