1. 程式人生 > 其它 >CCF_CSP認證 A. Night at the Museum 博物館之夜

CCF_CSP認證 A. Night at the Museum 博物館之夜

技術標籤:CCF_CSP認證ccfcsp

先上程式碼為敬,題目和翻譯在後面
/* 
字母轉輪
題目詳情請google: CodeForces 731 A.Night at the Museum	
*/ 

#include <stdio.h>
#include <math.h>
int min(int a, int b);
void putsum(char *a, int *sum);

int main ()
{
	int sum = 0;
	char a[100];
	gets (a);
	puts (a);
	putsum(a, &sum);
	printf
("%d",sum); } void putsum(char *a, int *sum) { if (0 <= abs(*a - 'a') && abs(*a - 'a') < 13) *sum = abs(*a - 'a'); if (13 <= abs(*a - 'a') && abs(*a - 'a') < 26) *sum = 26 - abs(*a - 'a'); for (int i = 0; *(a+i) != '\0'; i++) { if (0 <= abs(*(a+i) - *(
a+i+1)) && abs(*(a+i) - *(a+i+1)) < 13)//順時針 *sum += abs(*(a+i) - *(a+i+1)); if (13 <= abs(*(a+i) - *(a+i+1)) && abs(*(a+i) - *(a+i+1)) < 26)//逆時針 *sum += 26 - abs(*(a+i) - *(a+i+1)); *(a+i) = *(a+i+1); } }
原版題目:

A. Night at the Museum

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.

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

Copy

zeus

output

Copy

18

input

Copy

map

output

Copy

35

input

Copy

ares

output

Copy

34

Note

在這裡插入圖片描述

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.

翻譯

A. 博物館之夜

格里戈裡和一部著名喜劇片的英雄一樣,在博物館找到了一份夜間保安的工作。第一天晚上,他收到了浮雕,並盤點了整個博覽會。

浮雕是一種特殊的設計,允許"列印"塑料膠帶的文字。文字按字元順序列印。該裝置由一個輪子組成,其小寫英文字母用圓圈書寫,靜態指標指向當前字母,以及列印所選字母的按鈕。一次移動,允許順時針或逆時針旋轉字母輪。最初,靜態指標指向字母"a"。其他字母的位置如圖片所示:

在這裡插入圖片描述

格里戈裡將新物品新增到底座後,他必須將其名稱列印在塑料膠帶上,並將其附加到相應的展品上。它不需要返回車輪到其初始位置與指標上的字母’a’。

我們的英雄擔心一些展品會活著,開始攻擊他,所以他想盡快列印名字。幫助他,為給定的字串找到列印所需的車輪最小旋轉數。

輸入

唯一的輸入行包含某些展覽的名稱 - 非空字串,包含不超過100 個字元。它保證字串只由小寫英語字母組成。

輸出

列印一個整數 – 列印輸入中給出的名稱所需的車輪最小旋轉數。

例子

輸入

複製

宙斯

輸出

複製

18

輸入

複製

地圖

輸出

複製

35

輸入

複製

阿瑞斯

輸出

複製

34

注意

在這裡插入圖片描述

要從第一個樣本列印字串,最好執行以下旋轉序列:

\1. 從"a" 到 “z”(1 次逆時針旋轉),

\2. 從[z]到[e](5 次順時針旋轉),

\3. 從[e]到[u](逆時針旋轉 10 次),

\4. 從\u\到\s\(2 逆時針旋轉) 。

總共需要1 + 5 + 10 + 2 + 18 次旋轉。