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. java分布式服务框架Dubbo的介绍与使用

    1. Dubbo是什么? Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案.简单的说,dubbo就是个服务框架,如果没有分布式的需求,其实是不需 ...

  2. English - every和each的用法和区别

    两者都有“每个”的意思,但用法不同: (1)each具有名词和形容词的功能,every只有形容词的功能. (2)each指两个或两个以上的人或事物中的“每个”:every是指三个以上的人或事物的“全体 ...

  3. Windows Server 中开启 SQL Server 2008 的1433端口

    在Windows Server2008 服务器上部署了Microsofit SQL Server2008 R2 ,想让远程机器能够访问,于是开放1433端口,进行了如下设置: 1.打开“本地安全策略” ...

  4. G - 好老师

    G - 好老师 Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu Submit Statu ...

  5. poj 1321 棋盘问题 递归运算

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19935   Accepted: 9933 Description ...

  6. hdu3033I love sneakers! (分组背包,错了很多次)

    Problem Description After months of hard working, Iserlohn finally wins awesome amount of scholarshi ...

  7. 美化 input type=file控件

    大家都知道input的type=file控件默认样式是不能修改的 可以通过一个小技巧处理下 html: <a href="javascript:;" class=" ...

  8. 如何重启MySQL服务,正确重启mysql

    RedHat Linux (Fedora Core/Cent OS) 1.启动:/etc/init.d/mysqld start 2.停止:/etc/init.d/mysqld stop 3.重启:/ ...

  9. ECC(Error Checking and Correction)校验和纠错

    ECC的全称是 Error Checking and Correction or Error correction Coding,是一种用于差错检测和修正的算法.上一节的BBM中我们提到过,NAND闪 ...

  10. WPF中如何获取ControlTemplate中的对象

    原文 http://www.silverlightchina.net/html/study/WPF/2010/1116/3418.html 先看一段XAML代码: 1 2 3 4 5 6 7 8 9 ...