CodeForces 731 A.Night at the Museum(水~)

来源:互联网 发布:韶关市网络问政门户 编辑:程序博客网 时间:2024/05/16 13:53

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 111char 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;}
0 0
原创粉丝点击