Problem Description
Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some ways, she will type the key at least. But she has a bad habit that if the caps lock is on, she must turn off it, after she finishes typing. Now she wants to know the smallest times of typing the key to finish typing a string.
 
Input
The first line is an integer t (t<=100), which is the number of test case in the input file. For each test case, there is only one string which consists of lowercase letter and upper case letter. The length of the string is at most 100.
 
Output
For each test case, you must output the smallest times of typing the key to finish typing this string.
 
Sample Input
3
Pirates
HDUacm
HDUACM
 
Sample Output
8
8
8

Hint

The string “Pirates”, can type this way, Shift, p, i, r, a, t, e, s, the answer is 8.
The string “HDUacm”, can type this way, Caps lock, h, d, u, Caps lock, a, c, m, the answer is 8
The string "HDUACM", can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8

题意:要求一个字符串输入,按键盘的最少次数。有Caps Lock和Shift两种转换大小写输入的方式

思路:用dpa与dpb数组分别记录Caps Lock的开关状态

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; char str[111];
int dpa[111],dpb[111]; int main()
{
int t,i,len,flag;
scanf("%d",&t);
while(t--)
{
scanf("%s",str+1);
dpa[0] = 0;
dpb[0] = 1;
for(i = 1; str[i]; i++)
{
if(str[i]>='a' && str[i]<='z')
{
dpa[i] = min(dpa[i-1]+1,dpb[i-1]+2);//若灯亮,则直接按字母;若灯灭,则按字母再开灯
dpb[i] = min(dpa[i-1]+2,dpb[i-1]+2);//若灯亮,则要先按字母再关灯;若灯灭,则按shift+字母
}
else if(str[i]>='A' && str[i]<='Z')
{
dpa[i] = min(dpa[i-1]+2,dpb[i-1]+2);
dpb[i] = min(dpa[i-1]+2,dpb[i-1]+1);
}
}
printf("%d\n",min(dpb[i-1]+1,dpa[i-1]));//最后要关灯,dpb要+1
} return 0;
}

HDU2577:How to Type(DP)的更多相关文章

  1. HDU 2577 How to Type (DP,经典)

    题意: 打字游戏,求所按的最少次数.给出一个串,其中有大小写,大写需要按下cap键切换到大写,或者在小写状态下按shift+键,这样算两次,打小写时则相反.注意:在打完所有字后,如果cap键是开着的, ...

  2. POJ1463:Strategic game(树形DP)

    Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...

  3. 计蒜客模拟赛D1T3 蒜头君的坐骑:用dfs转移dp

    题目链接:https://nanti.jisuanke.com/t/16447 题意: 蒜头君有一只坐骑,人马. 一天,蒜头君骑着他的坐骑走上了一片n*m的大荒野,一开始时,蒜头君在(1,1)点,他要 ...

  4. 【转】JAVA错误:The public type *** must be defined in its own file***

    出现The public type xxx must be defined in its own file这个问题,是由于定义的JAVA类同文件名不一致.public类必须定义在它自己的文件中. 解决 ...

  5. QTCreator 调试:unknown debugger type "No engine"

    [1]QTCreator调试,应用程序输出:unknown debugger type "No engine" 如图:下断点->调试程序->应用程序输出 说明:调试器无 ...

  6. delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决

    delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决,需要打这个 ...

  7. HTML5学习笔记简明版(5):input的type超级类型

    HTML5为input的type类型添加了多种枚举值,用来表达不同的意思.同事具有验证功能,假设格式不正确,浏览器将原始提供错误提示,堪称超级牛X啊,详细例如以下: Keyword Data type ...

  8. Codeforces 730J:Bottles(背包dp)

    http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...

  9. Numpy版本问题,import tensorflow as tf 报警:“ FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'”

    tensorflow成功安装后 import tensorflow as tf 报警:“ FutureWarning: Passing (type, 1) or '1type' as a synony ...

随机推荐

  1. css3 动画(animation)-简单入门

    css3之动画(animation) css3中我们可以使用动画,由于取代以前的gif图片,flash动画,以及部分javascript代码(相信有很多同学都用过jquery中的animate方法来做 ...

  2. 开源libusb驱动的libwdi驱动安装API库和zadig.exe安装UI应用程序的编译和调试

    一.目的 二.编译环境 系统:Win7 ~ Win10 编译工具:Visual Studio 2008 或 Visual Studio 2010 或Visual Studio 2015 libwdi编 ...

  3. Fedora安装theano

    Fedora下安装theano Fedora下安装theano Theano的安装依赖很多包,有必须的,有可选的.此外,python版本必须大于2.6,请在shell直接键入python,如果小于2. ...

  4. 5.7.1.4 window对象

    ECMAScript虽然没有指出如何直接访问Global对象,但web浏览器都是将这个全局对象作为window对象的一部分加以实现的.因此,在全局作用域中声明的所有变量和函数,就都成为了window对 ...

  5. symfony2 关于是否需要建立多bundle

    http://blog.danielribeiro.org/yes-you-can-have-low-coupling-in-a-symfony-standard-edition-applicatio ...

  6. 查看、修改oracle字符集,查看oracle版本

    1.查看数据库字符集 数据库服务器字符集select * from nls_database_parameters,其来源于props$,是表示数据库的字符集. 客户端字符集环境select * fr ...

  7. 6_StopWatch

    6 // // ViewController.swift // StopWatch // // Created by ZC on 16/1/9. // Copyright © 2016年 ZC. Al ...

  8. 阿里云ECS每天一件事D7:安装tomcat8.0

    这一D,跨越了几个月啊,人是越来越懒,集中写一些,就懒得再记录了.也是因为测试需要,搭建个jsp的服务环境,只是测试,考虑用tomcat就够了. 在Tomcat官网下载最新Core版本,下载之后,将文 ...

  9. php环境配置优化

    Php相关配置 – 基础 max_execution_time = 30 max_input_time = 60 memory_limit = 128 Mmax_input_vars = 1000 r ...

  10. android 关于多任务下载问题

    关于多任务下载问题    近期项目中,遇到一个问题,列表数据中的图片地址是一个需要下载JS再解析的字段,之前的图片下载是一个异步的过程,由一个队列处理. Android系统以不同寻常的方式处理多个应用 ...