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. ubuntu内窗口最大最小化

    我用的dell笔记本,开始的时候,需要修改dell笔记本的BIOS,里面有一个 Funtion Key 一开始定义的行为是多媒体的,需要改成默认行为,具体记不清了, 反正知道这个,肯定知道哪里找. 然 ...

  2. cygwin 运行java的一些记录

    javac编译没问题,但是java执行就不行,处理方式如下 其实就是把宿主机下的java.exe在cygwin下搞一个快捷方式 关于路径问题,可以使用cygpath命令进行宿主机和cygwin间的转换 ...

  3. android.view.animation(3) - LayoutAnimationController 和 GridLayoutAnimationController

    前几篇给大家讲述了如何针对某一个控件应用动画,这篇将给大家讲解如何给容器中的控件应用统一动画.即在容器中控件出现时,不必为每个控件添加进入动画,可以在容器中为其添加统一的进入和退出动画. 从上面的示例 ...

  4. android.view.animation(1) - alpha、scale、translate、rotate、set的xml属性和用法(转)

    一.ScaleAnimation ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, floa ...

  5. 167. Add Two Numbers【easy】

    You have two numbers represented by a linked list, where each node contains a single digit. The digi ...

  6. makefile之include

    "include"指示符告诉 make 暂停读取当前的 Makefile,而转去读取"include"指定的一个或者多个文件,完成以后再继续当前 Makefil ...

  7. 04、Quick Start for Windows

    创建一个新工程 1.在 VS 上,选择 File > New > Project.. 2.在新工程窗口,选择  Visual C# > Windows Store > Blan ...

  8. ThreadPool has stuck threads

    weblogic 10后台出现警告,原因:ThreadPool has stuck threads 在WEBLOGIC中如果一个线程执行时间超过了Stuck Thread Max Time规定的时间, ...

  9. 80X86寄存器介绍

    80X86寄存器介绍  32位CPU所含有的寄存器有: 4个数据寄存器(EAX.EBX.ECX和EDX)2个变址和指针寄存器(ESI和EDI) 2个指针寄存器(ESP和EBP)6个段寄存器(ES.CS ...

  10. Bootstrap学习笔记(2)--栅格系统深入学习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...