题目链接

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

分析:

多注意一些细节问题。

代码:

#include <stdio.h>
#include <string.h>
int isA(char c)
{
return c>='A'&&c<='Z';
}
int main()
{
int n,len,c;
int i,j;
char s[105];
int caplock;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
c=len=strlen(s);
caplock=0;
for(i=0; i<len; i++)
{
int t=isA(s[i]);
for(j=i+1; j<len; j++)
{
if(t!=isA(s[j]))break;
}
if(t==1&&caplock==0&&j-i<2)//只有一个大写字母,Cap键没有按下
c++;//按shift键
else if(t==1&&caplock==0&&j-i>=2)//有多于1个大写字母,Cap键没有按下
c++,caplock=1;//按下Cap键
else if(t==0&&caplock==1&&j-i<2&&j==len)//结尾有一个小写字母,Cap已经按下
c++,caplock=0;//按下Cap键
else if(t==0&&caplock==1&&j-i<2)//Cap已经按下,出现一个小写字母
c++;//按shift键
else if(t==0&&caplock==1&&j-i>=2)//Cap已经按下,出现多个小写字母
c++,caplock=0;//按下Cap键
i=j-1;
}
if(caplock)c++;
printf("%d\n",c);
}
}

HDU 2577 How to Type (字符串处理)的更多相关文章

  1. HDU 2577 How to Type (字符串处理)

    题目链接 Problem Description Pirates have finished developing the typing software. He called Cathy to te ...

  2. HDU 2577 How to Type (线性dp)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  3. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  4. HDU 2577 How to Type DP也可以模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=2577 大意: 大家都打过字吧,现在有个有趣的问题:给你一串字符串,有大写有小写,要求你按键次数最少来输出它,输出 ...

  5. hdu 2577 How to Type(DP)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU 2577 How to Type【DP】

    题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...

  7. hdu 2577 How to Type(dp)

    Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...

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

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

  9. DP问题(1) : hdu 2577

    题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...

随机推荐

  1. HDU 2133 What day is it

    http://acm.hdu.edu.cn/showproblem.php?pid=2133 Problem Description Today is Saturday, 17th Nov,2007. ...

  2. 利用闭包判断Dom元素和滚动条的方向

    本文收集整理自网上. 一,判断滚动条的方向,利用闭包首先保存滚动条的位置,然后当滚动时候不断更新滚动初始值,然后通过差指判断方向 function scroll(fn) { //利用闭包判断滚动条滚动 ...

  3. 【Docker 命令】- images命令

    docker images : 列出本地镜像. 语法 docker images [OPTIONS] [REPOSITORY[:TAG]] OPTIONS说明: -a :列出本地所有的镜像(含中间映像 ...

  4. 【Docker 命令】- start/stop/restart命令

    docker start:启动一个或多少已经被停止的容器 docker stop:停止一个运行中的容器 docker restart :重启容器 语法: docker start [OPTIONS] ...

  5. 阻塞 , 非阻塞 , 同步 ,异步 , I/O模型

    •阻塞,非阻塞:进程/线程要访问的数据是否就绪,进程/线程是否需要等待: •同步,异步:访问数据的方式,同步需要主动读写数据,在读写数据的过程中还是会阻塞:异步只需要I/O操作完成的通知,并不主动读写 ...

  6. Matlab 中的varargin/nargin varargout/nargout

    Varargin = var+ arg+ in = variable length(可变长) input argument(输入参数) list(列表) :允许调用该函数时根据需要改变输入参数的个数 ...

  7. 基本数据类型(int,bool,str)

    目录: 1.int        数字类型 2.bool      布尔值 3.str    字符串类型 一.整型(int) 在python3中所有的整数都是int类型.但在python2中如果数据量 ...

  8. lambda 分组练习

    public partial class Form1 : Form { public Form1() { InitializeComponent(); } List<Person> per ...

  9. CodeChef LEMOVIE

    题意:给你n个数字(下标不同数值相同的数字应当被认为是不同的数字),有n!种排列方式.每种排列方式的价值定义为:第一次出现时比前面的所有数字都大的数值个数. 比如1,2,2,3这个排列中,1,2,3这 ...

  10. Django 2.0 学习(10):Django 定制化

    定制化admin表单 通过使用admin.site.register(Question)注册Question模型,Django可以构造默认的表单.通常,可以通过对象的注册机制来告诉Django我们想要 ...