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 ...
随机推荐
- 1、Reactive Extensions for .NET(译)
注:本文的工程是基于 vs2010 的,在 vs2012 中区别不大. 本文的意图是让读者熟悉 Reactive Extension for .net(Rx) 的使用.通过一系列的例子,让读者感受 基 ...
- [转]James Bach:测试人员的角色
[转]James Bach:测试人员的角色 2015-05-13 以前,我是个开发人员.我不喜欢这个工作,无尽的压力让我疲惫.我几乎从未感觉到自己的工作做得足够好.我从未有过真正的休息.如果我没做好, ...
- std::string与output-operator"<<"的兼容问题
经查阅资料得知,“在某些编译器下std::string,需要使用c_str()才能作为output-operator "<<" 的参数” std::string tit ...
- 在无法单步调试的情况下找Bug的技巧
比如说你有一个大的模块A,其组成部分有B,C,D这3个小的模块,现在A出了一个BUG,因为某种原因的限制你无法单步调试.怎么较快地定位BUG发生的根源? 这里记录一下刚才我在找BUG的时候采用的思路, ...
- Mysql定时备份数据脚本
项目集群搭建完成,数据库虽有做主从同步,但考虑到数据安全性,为了满足这个需求那么要每天对数据备份处理, 但每天手动进行备份处理太过于被动,而且白天用户访问,会有数据变化以及在备份时会影响服务器正常运行 ...
- oracle 存储过程学习感悟
1.跟大白话差不多 2.if...then.... else ....写的比较多 3.调用存储过程命令:execute procedure_name 4.调用存储函数命令:select '0' str ...
- Linux下C语言编程中库的使用
零.问题 1. 为什么要用到库? 2. 我要用一个库,但是,尼玛命令行上该怎么写呢?或者说库文件如何使用? 3. Linux的库在那些地方? 4. 什么是静态库,什么是动态库,二者有啥区别? 5. 常 ...
- 去除inline-block元素间间距的N种方法<转>
一.现象描述 真正意义上的inline-block水平呈现的元素间,换行显示或空格分隔的情况下会有间距,很简单的个例子: <input /> <input type="su ...
- 数学分析 + 容斥原理 - URAL 1907 Coffee and Buns
Coffee and Buns Problem's Link: http://www.bnuoj.com/v3/contest_show.php?cid=6415#problem/H Mean: 给定 ...
- Linux系统下如何查看物理内存占用率
Linux系统下如何查看物理内存占用率 Linux下看内存和CPU使用率一般都用top命令,但是实际在用的时候,用top查看出来的内存占用率都非常高,如:Mem: 4086496k total, ...