CF731A.Night at the Museum

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser 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.

格里戈里像某部著名喜剧电影中的主角一样,找到了一份博物馆夜间保安的工作。第一个晚上,他领到了一台压印机,需要清点整个展览品。

压印机是一种特殊的设备,可将文本“打印”在塑料胶带上。文本按字符顺序逐个打印。该设备由一个圆盘组成,圆盘上按环形排列着小写英文字母,另有一个指向当前字母的固定指针,以及一个用于打印所选字母的按钮。每次操作允许将字母圆盘顺时针或逆时针旋转一格。初始状态下,固定指针指向字母 'a'。其余字母的排列方式如图所示:

每当格里戈里向数据库中添加一件新展品时,他必须在塑料胶带上打印其名称,并将其附在对应展品上。无需将圆盘复位至初始状态(即指针不必回到 'a')。

我们的主角担心某些展品可能会“活过来”并攻击他,因此他希望尽可能快地完成名称打印。请帮助他:对于给定的字符串,求出打印它所需的最小轮盘旋转次数。

输入格式

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.

输入仅有一行,包含某个展品的名称——一个非空字符串,长度不超过 100 个字符。保证该字符串仅由小写英文字母组成。

输出格式

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

输出一个整数——打印输入中给出的名字所需的轮子最小旋转次数。

输入输出样例

  • 输入#1

    zeus

    输出#1

    18
  • 输入#2

    map

    输出#2

    35
  • 输入#3

    ares

    输出#3

    34

说明/提示

To print the string from the first sample it would be optimal to perform the following sequence of rotations:

  1. from 'a' to 'z' (1 rotation counterclockwise),
  2. from 'z' to 'e' (5 clockwise rotations),
  3. from 'e' to 'u' (10 rotations counterclockwise),
  4. from 'u' to 's' (2 counterclockwise rotations).

In total, 1 + 5 + 10 + 2 = 18 rotations are required.

要打印第一个样例中的字符串,执行以下旋转序列是最优的:

  1. 从 'a' 到 'z'(逆时针旋转 1 次),
  2. 从 'z' 到 'e'(顺时针旋转 5 次),
  3. 从 'e' 到 'u'(逆时针旋转 10 次),
  4. 从 'u' 到 's'(逆时针旋转 2 次)。

总共需要 1+5+10+2=181 + 5 + 10 + 2 = 18 次旋转。

输入解题思路,AI测评打分。不知道怎么写?

首页