题目链接

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. iOS- 用MapKit和CoreLocation 来实现移动设备(地图与定位)

    1.前言 发现在很多的社交软件都引入了地图和定位功能,如果我们要想实现这两大功能,需要利用到两个框架:MapKit和CoreLocation   我们先来看看CoreLocation框架:   它可以 ...

  2. erlang+thrift配合开发

    I  think, thrift is a  tcp/ip based Client-Server architecture multi-languages supported RPC framewo ...

  3. 3dContactPointAnnotationTool开发日志(八)

      今天上午去实验室打算把项目从github上pull下来发现貌似不行,然后强行pull下来后项目变得乱七八糟了,有的组件都不知道去哪里了.去github上看了看发现上面day6和day7都没有,特别 ...

  4. lol人物模型提取(三)

      提取出来的lol人物模型能让你知道一些有趣的信息,比如说给英雄量个身高啥的.   经测量,佐伊的身高应大于1m60,比想象中的着实高不少啊.   然后还应该把这个模型镜像对称一下,在3dsmax里 ...

  5. Agile.Net 组件式开发平台 - 驱动开发示例

    首先讲一下概念,此驱动非彼驱动.在Agle.Net中我们将组件规划成两种类型,一种是基于业务的窗体组件,一种是提供扩展功能的驱动组件. 打个比方例如一般系统中需要提供身份证读卡功能,然而市面上有很多种 ...

  6. 给MySQL字段添加索引的操作

    1.添加PRIMARY KEY(主键索引): ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索引) : ALTE ...

  7. jira & analytics

    jira & analytics jira 代码有毒呀 http://jira.xgqfrms.xyz:8888/rest/analytics/1.0/publish/bulk { resou ...

  8. query 获取本身的HTML

    <div class="test"><p>hello,你好!</p></div> <script> $(".t ...

  9. zoj3209-Treasure Map

    给出一个左下角为\((0,0)\),右上角为\((n,m)\)的矩形,再给出\(k\)个在大矩形内的小矩形(可以重合),问是否能用这些小矩形完全覆盖这个大矩形,并且没有重合,如果可以至少需要多少个. ...

  10. BZOJ 1996 合唱队(DP)

    考虑从最后的队形开始依次还原最初的队形. 对于当前的队形,要么选最左边的,要么选最右边的. 如果选了左边的,那么下次选择的一定是大于它的.右边的同理. 所以定义dp[mark][l][r]为区间[l, ...