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
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 暴力的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 贪心 Codeforces Round #289 (Div. 2, ACM ICPC Rules) B. Painting Pebbles
题目传送门 /* 题意:有 n 个piles,第 i 个 piles有 ai 个pebbles,用 k 种颜色去填充所有存在的pebbles, 使得任意两个piles,用颜色c填充的pebbles数量 ...
- 递推水题 Codeforces Round #289 (Div. 2, ACM ICPC Rules) A. Maximum in Table
题目传送门 /* 模拟递推水题 */ #include <cstdio> #include <iostream> #include <cmath> #include ...
- 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. ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- 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 ...
随机推荐
- K2 blackpearl 流程开发(二)
转:http://blog.csdn.net/gxiangzi/article/details/8444590 本来想一篇文章把流程开发介绍完的,后来发现实在是太多了,只好分成两部分了.上一篇很简单的 ...
- getDeclaredMethods()和getMethods()区别
getDeclaredMethods() 返回 Method 对象的一个数组,这些对象反映此 Class 对象表示的类或接口声明的所有方法,包括公共.保护.默认(包)访问和私有方法, ...
- 给IT新男的15点建议:苦逼程序员的辛酸反省与总结
很多人表面上看着老实巴交的,实际上内心比谁都好强.自负.虚荣.甚至阴险.工作中见的多了,也就习惯了. 有一些人,什么事都写在脸上,表面上经常得罪人,甚至让人讨厌.但是他们所表现的又未必不是真性情. 我 ...
- RESTLET开发实例(一)基于JAX-RS的REST服务
RESTLET介绍 Restlet项目为“建立REST概念与Java类之间的映射”提供了一个轻量级而全面的框架.它可用于实现任何种类的REST式系统,而不仅仅是REST式Web服务. Restlet项 ...
- 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
使用HttpURLConnection下载文件时经常会出现 java.io.FileNotFoundException文件找不到异常,下面介绍下解决办法 首先设置tomcat对get数据的编码:con ...
- PHP中的替代语法
今天看了一下wordpress的代码,里面有些少见的php替代语法, <?php else : ?> <div class="entry-content"> ...
- c++ 概念及学习/c++ concept&learning(三)
这一篇继续说说程序设计中的基本语句:控制块 一 if类控制语句 if if else if , else if ,else if(条件语句){如果条件为真,要做的一些事情} if(条件语句) {如 ...
- sql-case列转行
1:对列进行逻辑判断 select ID,Score, case when Score>=90 then 'A' when Score>=80 then 'B' when Score> ...
- java的动态代理机制
前几天看到java的动态代理机制,不知道是啥玩意,然后看了看.死活不知道 invoke(Object proxy, Method m, Object[] args)种的proxy是个什么东西,放在这里 ...
- 现代程序设计——homework-08
写在前面 以下内容出自一个对C++只有一点点了解,几乎没有写过C++程序的人,理解上的一定会很不到位,请各位路过神牛多多指点. 博客内容为对 http://www.cnblogs.com/softwa ...