每次找到最短距离,然后更新指针的位置。

AC代码:

#include<cstdio>
#include<cmath>
const int maxn=100+5;
char s[maxn];
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	while(scanf("%s",s)!=EOF){
		int ans=0;
		int po=0;
		for(int i=0;s[i]!='\0';++i){
			ans+=min(fabs(s[i]-'a'-po),26-fabs(s[i]-'a'-po));
			po=s[i]-'a';
		}
		printf("%d\n",ans);
	}
	return 0;
}

如有不当之处欢迎指出!

CodeForces-731A的更多相关文章

  1. CodeForces 731A Night at the Museum

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. CodeForces 731A Night at the Museum (水题)

    题意:给定一个含26个英语字母的转盘,问你要得到目标字符串,至少要转多少次. 析:分别从顺时针和逆时针进行,取最小的即可. #pragma comment(linker, "/STACK:1 ...

  3. 【87.65%】【codeforces 731A】Night at the Museum

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  10. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. python_猜年龄

    猜年龄,有三次机会,如何做? 1. 检查 输入的数据是否合法,通过异常try来处理,并记录 输入错误次数 2. 通过累加器,判断是否猜了3次,并提示还剩余多少的机会 3. 当3次错误,跳出 #!/us ...

  2. Java常用类--数字常用类

    math java提供了基本的 + - * / %等基本算术运算的运算符,但对于更复杂的数学运算比如:三角函数,对数运算,指数运算就无能为力了.Java提供了Math工具类来完成这些复杂的运算,Mat ...

  3. maven-assembly-plugin插件的使用方法

    一. Assembly 是什么意思? 二. maven-assembly-plugin是什么? 它是maven中针对打包任务而提供的标准插件. 三. maven-assembly-plugin插件的作 ...

  4. 02_HTML5+CSS详解第四天

    依旧是CSS部分贴个CSS主要知识点总结的链接:http://blog.csdn.net/html5_/article/details/26098273 [自己的笔记做得好乱,以前一直以为是字丑的原因 ...

  5. http常见状态码(转载)

    常见HTTP状态码 常见HTTP状态码 200 OK 301 Moved Permanently 302 Found 304 Not Modified 307 Temporary Redirect 4 ...

  6. shell的变量处理

    shell的变量处理 一.删除 删除(删除某一段) # 从前向后删除 % 从后向前删除 删除(删除某一部分) $(var:nu1:nu2) nu1表示开始位置 nu2表示删除长度 示例如下 file= ...

  7. 【转】GPS静态观测网的设计指标

     GPS网的设计指标是指导GPS网设计量化因子,是评价GPS网设计优劣的数值标准.评价GPS网设计的优劣主要从以下三个因素考虑:1.质量(包括精度和可靠性):2.效率:3.费用. 一.GPS网设计的精 ...

  8. python --- mulitprocessing(多进程)模块使用

    1. 什么是进程? 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本执 ...

  9. Git Batch命令(转)

    echo 和 @ 回显命令 @ #关闭单行回显 echo off #从下一行开始关闭回显 @echo off #从本行开始关闭回显.一般批处理第一行都是这个 echo on #从下一行开始打开回显 e ...

  10. 使用open-falcon监控Nginx

    一.介绍 前段时间部署试用了open-falcon v0.2,官方文档很详细,难度也不是很大.监控Nginx也参考了文档推荐的方式,文档地址:http://book.open-falcon.org/z ...