国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

HDU 2577

2019-11-14 10:14:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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數(shù)組分別表示cap鍵開(kāi)關(guān)狀態(tài),在完成第i個(gè)字母的最少步驟有兩種可能,在cap開(kāi)和關(guān)狀態(tài),在第i-1個(gè)字母完成時(shí),有兩種可能,一種是cap鍵開(kāi),一種是關(guān),每次取i-1狀態(tài)步驟的最小值,最后比較兩種狀態(tài)下,哪一種步驟最少。

#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]));//燈亮著要關(guān)滅 	}	return 0;}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江陵县| 富裕县| 临城县| 河津市| 南安市| 安福县| 玉山县| 清水河县| 郁南县| 冷水江市| 阿拉善右旗| 林西县| 铜山县| 额尔古纳市| 贺州市| 柳河县| 中宁县| 南雄市| 石台县| 寻甸| 松滋市| 治县。| 高清| 巩义市| 平塘县| 乳山市| 沙坪坝区| 黎城县| 阳西县| 会昌县| 信阳市| 新龙县| 桑日县| 尼木县| 罗甸县| 会同县| 于田县| 吉木萨尔县| 镇康县| 轮台县| 凌云县|