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. C#导出Word或Excel文件总显示Html标记

    原因:Word或Excel文件包含的GridView没有查询到数据.

  2. Android知识简单测试题

    上周去了一场Android考试,前面基础的题目很简单却答不上来,看过跟做过,懂了和会讲差距还是很大的,下面整理一下还记得的几个问题,自勉! 还是觉得,要好好看官方文档才是正道的啊! 1. Androi ...

  3. ASP.NET动态生成图片样式的验证码

    我们在设计用户登录模块时,经常会用到验证码,可以有效地防止黑客软件的恶意破解. 在此我就直接放置一个网页链接,以后用的时候可以当做备忘! 此连接中有多种验证码图片的样式可供参考. http://www ...

  4. JavaScriptの例

    Dateのオブジェクト: <html> <head> <title>Date Object Example</title> </head> ...

  5. poj 1966 Cable TV Network 顶点连通度

    题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通.随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全图 ...

  6. 有关extern的用法

    1.引言 C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同.作为一种欲与C兼容的语言, C++保留了一部分过程式 ...

  7. java中常用的数据加密算法

    以下为加密的工具类: import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; im ...

  8. 深入剖析PE文件

    不赖猴的笔记,转载请注明出处. 深入剖析PE文件 PE文件是Win32的原生文件格式.每一个Win32可执行文件都遵循PE文件格式.对PE文件格式的了解可以加深你对Win32系统的深入理解. 一.   ...

  9. 升级automake和autoconf

    <pre name="code" class="html">zjtest7-redis:/root/soft/json-c-json-c-0.12- ...

  10. POJ 3294 Life Forms(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=3294 [题目大意] 求出在至少在一半字符串中出现的最长子串. 如果有多个符合的答案,请按照字典序输出. [题解] 将所有的字符串通 ...