麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

HDU 2577

2019-11-14 09:40:56
字體:
來源:轉載
供稿:網友

How to Type

Time Limit: 2000/1000 MS (java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6440 Accepted Submission(s): 2909PRoblem DescriptionPirates 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.InputThe 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.OutputFor each test case, you must output the smallest times of typing the key to finish typing this string.Sample Input
3PiratesHDUacmHDUACMSample Output
888HintThe 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 8The string "HDUACM", can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8思路:dpa與dpb數組分別表示cap鍵開關狀態,在完成第i個字母的最少步驟有兩種可能,在cap開和關狀態,在第i-1個字母完成時,有兩種可能,一種是cap鍵開,一種是關,每次取i-1狀態步驟的最小值,最后比較兩種狀態下,哪一種步驟最少。

#include<stdio.h>#include<string.h>char str[110];int dpa[110],dpb[110]; //dpa[110]表示燈亮,dpb[110]表示燈滅 int Min(int a, int b) {	return a > b ? b : a; }int main() {	int t,i;	scanf("%d",&t);	getchar();	dpa[0] = 1;	dpb[0] = 0;	while(t--) {		scanf("%s",str + 1);		for(i = 1; str[i]; i++) {			if(str[i] >= 'a' && str[i] <= 'z') {				dpa[i] = Min(dpa[i-1] + 2, dpb[i-1] + 2);//如果燈亮,按shift+字母,燈滅,按字母+cap 				dpb[i] = Min(dpa[i-1] + 2, dpb[i-1] + 1);//如果燈亮,按cap+字母,燈滅,按字母 			}			else if(str[i] >= 'A' && str[i] <= 'Z') {				 dpa[i] = Min(dpa[i-1] + 1, dpb[i-1] + 2);//如果燈亮,按字母,燈滅,按cap+字母 				 dpb[i] = Min(dpa[i-1] + 2, dpb[i-1] + 2);//如果燈亮,按字母+cap,燈滅,按shift字母 			}		}		printf("%d/n",Min(dpa[i-1] +1, dpb[i-1]));//燈亮著要關滅 	}	return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 男女一边摸一边做羞羞视频免费 | 成人在线免费观看小视频 | 国产视频软件在线 | 国产精品久久久久久久久久iiiii | 久久av免费观看 | 久久男人 | 毛片视频在线免费观看 | 中文字幕国产欧美 | 欧美一区黄色 | 国产一级做a爱片在线看免 2019天天干夜夜操 | 亚洲免费毛片基地 | 久久福利小视频 | 精品一区二区在线观看视频 | 鲁丝片一区二区三区免费入口 | 中文字幕免费在线观看视频 | 成人综合一区二区 | 亚洲一级网站 | 免费看真人a一级毛片 | 91短视频版高清在线观看免费 | 99在线精品视频免费观看20 | 国产亚洲综合一区二区 | 国产日韩免费观看 | 欧美18一19sex性护士农村 | 国产精品毛片无码 | 亚洲小视频在线观看,com | 国产午夜精品在线 | 免费看日韩片 | 国色天香综合网 | 国产日韩中文字幕 | 偿还的影视高清在线观看 | 长泽雅美av | 精品亚洲视频在线 | 亚洲视频综合网 | 欧美精品亚洲人成在线观看 | va毛片| 精品69人人人人 | 一级成人欧美一区在线观看 | 免费a级网站 | 国产一区二区不卡 | 在线观看免费毛片视频 | 久久久久久久黄色片 |