题解 | #手机键盘#
手机键盘
http://www.nowcoder.com/practice/20082c12f1ec43b29cd27c805cd476cd
include<stdio.h>
include<string.h>
int KeyTable[26]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4};
int main()
{
char str[200];
while(scanf("%s",str)!=EOF)
{
int time=0;
int len=strlen(str);
for(int i=0;i<len;i++)
{
time+=KeyTable[str[i]-'a'];
if(i!=0&&str[i]-str[i-1]==KeyTable[str[i]-'a']-KeyTable[str[i-1]-'a'])
{
time+=2;
}
}
printf("%d",time);
}
}