CodeForces 731A Night at the Museum
1 second
256 megabytes
standard input
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.
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.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
zeus
18
map
35
ares
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的更多相关文章
- CodeForces 731A Night at the Museum (水题)
题意:给定一个含26个英语字母的转盘,问你要得到目标字符串,至少要转多少次. 析:分别从顺时针和逆时针进行,取最小的即可. #pragma comment(linker, "/STACK:1 ...
- 【87.65%】【codeforces 731A】Night at the Museum
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- codeforces 598D Igor In the Museum
题目链接:http://codeforces.com/problemset/problem/598/D 题目分类:dfs 题目分析:处理的时候一次处理一片而不是一个,不然会超时 代码: #includ ...
- 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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
- 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 ...
随机推荐
- mysql 开启慢查询 如何打开mysql的慢查询日志记录
mysql慢查询日志对于跟踪有问题的查询非常有用,可以分析出当前程序里有很耗费资源的sql语句,那如何打开mysql的慢查询日志记录呢,接下来将详细为您介绍 原文出自:http://www.jbxue ...
- windows 和 linux 安装 scrapyd 出现Not a directory site-packages/scrapyd-1.0.1-py2.7.egg/scrapyd/txapp.py
1 这是因为 scrapyd安装的时候没有 解压 对应的 egg而导致的文件找不到的错误. 2 解决的方法,找到 scrapyd-1.0.1-py2.7.egg 解压缩 里面 有一个 scrapy ...
- 【ActiveMQ】ActiveMQ在Windows的安装,以及点对点的消息发送案例
公司最近会用MQ对某些业务进行处理,所以,这次我下载了apache-activemq-5.12.0-bin把玩下. 基于练习方便需要,使用Windows的版本. 参考的优秀文章: activemq的几 ...
- 关于Safe DOG的文件上传bypass
Author:倾旋payloads@aliyun.com本文由科拉实验室成员倾旋原创文章 Part 1 分析 此文主要研究安全狗的数据包分析功能,由于很多人都认为安全狗是通过正则去匹配的,那么暂且那么 ...
- HDU 2110 Crisis of HDU
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- [启动]Linux启动流程rcN.d rcS.d rc.local等
Linux嵌入式相关项目走到最后很难避开要开机自启一些应用程序或者脚本等,最近也在帮助同事做这个事情,以前自己玩板子的时候都是较为随便的在/etc/rc.local中添加就可以了,但是项目的话还是走标 ...
- 递归删除子目录下所有.la后缀文件
删除当前目录及其子目录下的后缀名.la的所有文件 find ./ -name '*.la' | xargs rm -f
- SpringMVC 之类型转换Converter 源代码分析
SpringMVC 之类型转换Converter 源代码分析 最近研究SpringMVC的类型转换器,在以往我们需要 SpringMVC 为我们自动进行类型转换的时候都是用的PropertyEdito ...
- APP纯黑盒测试—某些可以试试的操作
一.多次快速点击一处功能入口: 该测试方法可以在某些应用中打开俩次目标界面,举一些具体一点的例子: 1.比如现在很多APP需要登陆,如果打开了俩次登录页面,就容易造成登录成功后应用跳转界面又是登录界面 ...
- C语言 百炼成钢24
/* 题目60:从键盘中输入一个不超过40个字符的字符串, 再输入3个位数(每次删除一个字符),删除对应 位数的字符,然后输出删除指定字符后的字符串. 输入:hellokityManGood 3 6 ...