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
zeus
Output
18
Input
map
Output
35
Input
ares
Output
34
Note

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

from ‘a’ to ‘z’ (1 rotation counterclockwise),
from ‘z’ to ‘e’ (5 clockwise rotations),
from ‘e’ to ‘u’ (10 rotations counterclockwise),
from ‘u’ to ‘s’ (2 counterclockwise rotations).
In total, 1 + 5 + 10 + 2 = 18 rotations are required.

题目大意是说给你一个字符串,从第一个开始,顺时针或者逆时针转到下一个位置,选取这两种方式里面最小的那个,求最后的总距离。暴力一下就好了。

AC代码

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{string str1,str;cin>>str1;str[0]='a';str+=str1;int cnt=0;for(int i=0;i<str.length();i++){int num1;if(i==0)num1=0;elsenum1=str[i-1]-'a';int num2=str[i]-'a';if(num1>num2)cnt+=min(num1-num2,26-num1+num2);elsecnt+=min(num2-num1,26-num2+num1);}cout<<cnt<<endl;return 0;
}

A-Night at the Museum 水题相关推荐

  1. 水题/poj 1852 Ants

    1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...

  2. HDU2673-shǎ崽(水题)

    如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...

  3. 图论刷水题记录(二)(最短路-----SPFA算法)

    继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...

  4. 图论刷水题记录(一)(最短路-----dijkstra算法)

    最近实在不知道干些什么,感觉自己除了水题什么都不会做,算了去刷一刷图论的水题吧本来想合起来一起发,想了想太长的话以后看起来也不方便,题目所以今天晚上就先发了dij部分,由上到下由易变难. 1.POJ ...

  5. hdu 2041:超级楼梯(水题,递归)

    超级楼梯Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. HDU2568 前进【水题】

    前进 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. CF Round #426 (Div. 2) The Useless Toy 思维 水题

    题目链接: http://codeforces.com/contest/834/problem/A 题目描述: 输入起始状态和结束状态和数列长度, 判断旋转方向是顺时针逆时针还是不合理 解题思路: 长 ...

  8. NUC1312 Sum【水题+数学题】

    Sum 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 认为自然数是从1-N.将每个数和+或-联系起来,然后计算这个表达式的值我们得到一个和S.这个问题 ...

  9. Codeforces 864 A Fair Game 水题

    题目链接: http://codeforces.com/problemset/problem/864/A 题目描述: 看不是是不是一串数中只有两种数且这两种数字的数量是相同的 解题思路: 水题, 水过 ...

最新文章

  1. vc 只有顶级窗口可以弹出窗口_如果你刚换了新电脑,这几个地方记得设置一下,电脑可以多用几年...
  2. vue源码解析pdf_Vue源码全面解析八 callHook函数(触发生命周期函数)
  3. Windows控制台程序处理消息编程实例二则
  4. 操作系统OS-分页、页表
  5. Linux CentOS下安装Oracle
  6. 【jQuery】smartMenu右键自定义上下文菜单插件(似web QQ)
  7. 关于在线机器学习ftrl_proximal_lr的二三件事
  8. 快速排序---计数排序
  9. 使用nginx反向代理解决前端跨域问题
  10. dijkstra + 优先队列(C++)
  11. 基于kubectl实现红队K8S模拟对抗
  12. PADS VX2.8 AD封装库转换PADS封装的方法
  13. Python量化交易学习笔记(39)——BaoStock股票数据下载
  14. bin文件无法生成,Error: Q0147E: Failed to create Directory ./Flora_GD32.bin\ER$$.ARM.__AT_0x000000C0: File
  15. 如何学习渗透测试:初学者教程
  16. Android中汉字转换为拼音
  17. 重磅!腾讯正式开源 Spring Cloud Tencent
  18. freeswitch 自定义application
  19. 【Git 问题及解决方案】gitee fatal: sha1 file ‘<stdout>‘ write error: Broken pipe(待更)
  20. 如何编写外挂 制作外挂 外挂教程

热门文章

  1. WIndow Document
  2. Struts2框架学习(二) Action
  3. Github使用之git回退到某个历史版本
  4. css3-自定义字体
  5. 控制台之console
  6. 【数据库开发】windows下hiredis的编译(主要是包括一些异步编程的错误)
  7. HDU 3328 Flipper 栈 模拟
  8. ‘char *' differs in levels of indirection from 'int'
  9. iOS插件化研究之一——JavaScriptCore
  10. [SmartFoxServer入门]服务器安装