HDU-2577-How to Type
http://acm.hdu.edu.cn/showproblem.php?pid=2577
很有趣的一题,给一组字符串,问最少按几次键盘可以打完
小写字母可在capslock不亮时打出,也可在capslock亮时,按shift打出
大写字母可在capslock亮时打出,也可在capslock不亮时,按shift打出
用两个数组,逐步计算每一字母的最小次数即可
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char str[105];
int on[105]; //caps lock亮
int off[105]; //caps lock不亮
int min(int x,int y)
{
return x<y?x:y;
}
int main()
{
int i,t,len;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
on[0]=1; //初始开灯
off[0]=0;
len=strlen(str);
for(i=0;i<len;i++)
{
if('a'<=str[i]&&str[i]<='z')
{
on[i+1]=min(on[i]+2,off[i]+2);
off[i+1]=min(on[i]+2,off[i]+1);
}
else
{
on[i+1]=min(on[i]+1,off[i]+2);
off[i+1]=min(on[i]+2,off[i]+2);
}
}
on[len]++; //最后将灯关了
printf("%d\n",min(on[len],off[len]));
}
return 0;
}
分享到:
相关推荐
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
算法-数塔(HDU-2084).rar
算术(HDU-6715).rar
算法-确定比赛名次(HDU-1285).rar
最短路(HDU-2544).rar
算法-连连看(HDU-1175)(包含源程序).rar
算法-命运(HDU-2571)(包含源程序).rar
算法-欧拉回路(HDU-1878)(包含源程序).rar
算法-免费馅饼(HDU-1176)(包含源程序).rar
算法-六度分离(HDU-1869)(包含源程序).rar
算法-迷宫城堡(HDU-1269)(包含源程序).rar
算法-排列2(HDU-1716)(包含源程序).rar