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. OC - 5.内存管理

    一.引用计数器 1> 栈和堆 栈 ① 主要存储局部变量 ② 内存自动回收 堆 ① 主要存储需要动态分配内存的变量 ② 需要手动回收内存,是OC内存管理的对象 2> 简介 作用 ① 表示对象 ...

  2. webui layout like desktop rich client

    similarity similarlike desktop js frameworklike extj js frameworklike rich client js frameworkjs lay ...

  3. 数学符号π (Pi)、Σ(Capital Sigma)、μ (Mu) 、σ(sigma)、∏(capital pi), ∫(Integral Symbol)的来历

    1.π (Pi; periphery/周长) March 14 marks Pi Day, the holiday commemorating the mathematical constant π ...

  4. C++中delete和delete[]的使用

    偶然的机会要使用到动态分配整形数组,怎么删除new出来的东西一时有点模糊(也许一直就不知道),于是在VS上试了试(写代码时经常用这种方法去验证模凌两可的东西),总结出来有两点. 1.基本数据类型new ...

  5. Redis 3.0.2集群搭建以及相关问题汇总

    Redis3 正式支持了 cluster,是为了解决构建redis集群时的诸多不便 (1)像操作单个redis一样操作key,不用操心key在哪个节点上(2)在线动态添加.删除redis节点,不用停止 ...

  6. DIV+CSS 网页布局之:一列布局

    1.网页布局 布局(layout)即对事物的全面规划和安排,页面布局是对页面的文字.图像或表格进行格式化版式排列.网页布局对改善网站的外观非常重要,又称版式布局,大多数网站会把内容安排到多个列中,就像 ...

  7. PHP 读json文件并转php配置文件

    <?php$c = file_get_contents('./cities_v2.json');$s = "<?php return " . var_export(js ...

  8. MAC 终端快捷建

    常用的快捷键: Ctrl + d        删除一个字符,相当于通常的Delete键(命令行若无所有字符,则相当于exit:处理多行标准输入时也表示eof) Ctrl + h        退格删 ...

  9. Eclipse+Tomcat WEB开发配置

    关键字:JDK,WEB,Eclipse,Tomcat OS: Windows 8.1 with update 1.下载安装JDK:http://www.oracle.com/technetwork/j ...

  10. 实现CodeFirst自动数据迁移无需命令

    本主题假设您掌握了实体框架中 Code First 迁移的基本知识. 借助自动迁移功能,您无需对您所做的每一个更改都在程序包管理器控制台中运行Update-Database 命令. 启用迁移 只需执行 ...