How to Type

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3261 Accepted Submission(s): 1509 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

思路:openclock[i]记录到i位置打开大写键时的最小按键次数,closeclock[i]记录到i位置时不打开大写键时最小按键次数,详见代码。



 #include<ctype.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#define MAX 111
using namespace std;
int closeclock[MAX], openclock[MAX];
char str[MAX];
int main(){
int c, len;
/* freopen("in.c", "r", stdin); */
scanf("%d", &c);
while(c--){
memset(str, , sizeof(str));
scanf("%s", str);
len = strlen(str);
openclock[] = ;
for(int i = len;i > ;i --) str[i] = str[i-];
for(int i = ;i <= len;i ++){
if(islower(str[i])){
openclock[i] = min(openclock[i-]+, closeclock[i-]+);
closeclock[i] = min(openclock[i-]+, closeclock[i-]+);
}else{
openclock[i] = min(openclock[i-]+, closeclock[i-]+);
closeclock[i] = min(openclock[i-]+, closeclock[i-]+);
}
}
openclock[len]++;
printf("%d\n", min(openclock[len], closeclock[len]));
}
return ;
}
 

HDOJ --- 2577的更多相关文章

  1. 【HDOJ】2577 How to Type

    DP. /* 2577 */ #include <cstdio> #include <cstring> #include <cstdlib> #define MAX ...

  2. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  6. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  7. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  8. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  9. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

随机推荐

  1. C# 内存法图像处理

    内存法通过把图像储存在内存中进行处理,效率大大高于GetPixel方法,安全性高于指针法. 笔者当初写图像处理的时候发现网上多是用GetPixel方法实现,提到内存法的时候也没有具体实现,所以笔者在这 ...

  2. Nuage SDN

    Nuage推出纯软件解决方案虚拟化业务平台(VSP)由三部分组成:虚拟化业务目录(VSD).虚拟化业务控制器(VSC)和虚拟路由与交换(VRS). VSD是业务/IT策略引擎,可提供业务模板与分析,每 ...

  3. 第5章标准I/O库总结

    1 fwide函数试图设置流的定向(流的定向决定了读写单字节还是多字节字符) int fwide(FILE *fp,int mode) 宽定向返回正值,字节定向返回负值,为定向返回0 已定向流不会改变 ...

  4. 切割TOMCAT日志

    tomcat的catalina.out日志如果不做操作的话,日志就会日积月累的不断增加.我刚入职的时候发现某台服务器的硬盘报警,排查之后我慌了,一个tomcat的日志居然有100G,这怎么可以,在网上 ...

  5. Makefile隐含规则和用到的默认变量

    如果要使用隐含规则生成你需要的目标,你所需要做的就是不要写出这个目标的规则.那么,make会试图去自动推导产生这个目标的规则和命令,如果make可以自动推导生成这个目标的规则和命令,那么这个行为就是隐 ...

  6. js hover放大效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. jquery 去掉重复项(splice,apply,push)

    /* js数组去掉重复项 var somearray = [1,1,2,2,3,3,4,4,'1']; somearray.check(); //somearray will return arr=[ ...

  8. 简洁代码---python---string

    判断字符串是否是回文的,即是否中心对称的: >>>return s[::-1] == s 对称返回True, 否则返回False

  9. C# 操作XML文件,用XML文件保存信息

    using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.IO ...

  10. android alipay(移动支付,异步通知发起失败,但是支付成功)

    问题1:移动支付 demo测试,支付成功,但是异步通知没发起,help notify_url 需要服务器地址,不是本地网址 问题2:这回 支付成功了.也返回到return_url了.但是页面显示验证失 ...