A. Night at the Museum
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he receivedembosser and was to take stock of the whole exposition.

Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters
written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'.
Other letters are located as shown on the picture:

After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.

Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.

Input

The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that
the string consists of only lowercase English letters.

Output

Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.

Examples
input
zeus
output
18
input
map
output
35
input
ares
output

34

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <algorithm> using namespace std;
char a[105];
int main()
{
char now;
scanf("%s",a);
now='a';
int ans=0;
for(int i=0;a[i];i++)
{
ans+=min(abs(a[i]-now),min(abs(a[i]+26-now),abs(now+26-a[i])));
now=a[i];
}
printf("%d\n",ans);
return 0;
}

CodeForces 731A Night at the Museum的更多相关文章

  1. CodeForces 731A Night at the Museum (水题)

    题意:给定一个含26个英语字母的转盘,问你要得到目标字符串,至少要转多少次. 析:分别从顺时针和逆时针进行,取最小的即可. #pragma comment(linker, "/STACK:1 ...

  2. 【87.65%】【codeforces 731A】Night at the Museum

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. codeforces 598D Igor In the Museum

    题目链接:http://codeforces.com/problemset/problem/598/D 题目分类:dfs 题目分析:处理的时候一次处理一片而不是一个,不然会超时 代码: #includ ...

  4. Codeforces 376A. Night at the Museum

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集

    D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...

  6. Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴

    题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...

  7. Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)

    题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...

  8. 【CodeForces - 598D】Igor In the Museum(bfs)

    Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...

  9. Codeforces 598D:Igor In the Museum

    D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. PCI-Express协议传输层读书笔记

    http://www.doczj.com/doc/35cb19633169a4517723a3d9-9.html

  2. [svc]ssh生成key不交互

    ssh-keygen -t rsa -f ~/.ssh/id_rsa -P "" 首次执行不交互 第二次再次执行会让输入y

  3. Secure REST API with oauth2 (翻译)

    http://blog.csdn.net/haiyan_qi/article/details/52384734 ******************************************** ...

  4. strcmp在CTF中的案例

    当strcmp比较出错的时候就会为null.null即为0故输出flag. strcmp(arr,str); ?test[]=1 <?php define('FLAG', 'pwnhub{THI ...

  5. FragmentTabHost的应用

    原创)FragmentTabHost的应用(fragment学习系列文章之二) 时间 2014-04-14 00:11:46  CSDN博客 原文  http://blog.csdn.net/flyi ...

  6. GuozhongCrawler看准网爬虫动态切换IP漫爬虫

    有些关于URL去重的方面代码没有提供,须要自己去实现.主要这里提供思路 项目地址:http://git.oschina.net/woshidaniu/GuozhongCrawler/tree/mast ...

  7. AtomicReference与volatile的区别

    首先volatile是java中关键字用于修饰变量,AtomicReference是并发包java.util.concurrent.atomic下的类.首先volatile作用,当一个变量被定义为vo ...

  8. datagrid.celltips.js

    /** * Created with JetBrains WebStorm. * User: cao.guanghui * Date: 13-6-26 * Time: 下午11:27 * To cha ...

  9. 按SCI影响因子排序的前50人工智能期刊列表

    附录二:按SCI影响因子排序的前50人工智能期刊列表 出版物名称,影响因子 IEEE TRANSACTIONS ON FUZZY SYSTEMS, 6.701    International Jou ...

  10. backbone.js初探(转)

    BackBone是JavaScript frameworks for creating MVC-like web applications,最近流行的用来建立单页面web application的工具 ...