Description
一个键盘如下:
问至少转多少格可以打出串s
Input
一个字符串s,串长不超过100
Output
输出打出s最少需要转多少格
Sample Input
zeus
Sample Output
18
Solution
简单题,每次顺时针转和逆时针转取个较小值
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 111
char s[maxn];
int main()
{
while(~scanf("%s",s))
{
int n=strlen(s),ans=0,pre=0;
for(int i=0;i<n;i++)
{
int t=s[i]-'a';
ans+=min(abs(t-pre),26-abs(t-pre));
pre=t;
}
printf("%d\n",ans);
}
return 0;
}