Codeforces_731_A

http://codeforces.com/problemset/problem/731/A

 

每次操作总共4种情况,判断一下就好了。

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

char s[105];

int main()
{
    int cnt = 0;
    char now = 'a';
    scanf("%s",s);
    int len = strlen(s);
    for(int i = 0;i < len;i++)
    {
        if(now <= s[i])    cnt += min(s[i]-now,now+26-s[i]);
        else    cnt += min(now-s[i],s[i]+26-now);
        now = s[i];
    }
    printf("%d\n",cnt);
    return 0;
}

 

posted @ 2016-10-17 00:09  zzzzzzzzhu  阅读(127)  评论(0编辑  收藏  举报