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

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. struts2 action 页面与action参数的传递的三种方式

    第一种: 初始页面: <form action="LoginAction.action" method="post"> 用户名:<input ...

  2. awk ‘! a[$0]++’ 去重

    awk '! a[$0]++' 怎么理解? 这是一个非常经典的去重复项的awk语句,虽然短小,不过涉及到了不少知识点,下面一一解读: <1> :"!" 即非. < ...

  3. JMeter基础教程2:正则表达式使用

    0. 正则表达式简介 正则表达式,又称规则表达式(Regular Expression,在代码中通常简写为regex.regexp或RE)描述了一种字符串匹配的模式(pattern),可以用来检查一个 ...

  4. 手把手的SpringBoot教程,SpringBoot创建web项目(一)

    1.引子 大家好,在接下里的半个多小时,我会给大家详细的介绍SpringBoot的基本使用,相信学完这门课程以后,你会对SpringBoot有一个清晰的认识,并且能够运用这门比较新颖的技术开发一些小程 ...

  5. java配置context.xml文件

    2018-02-08   23:32:23 修改context.xml文件 自从学习了servlet后,每次修改里面的内容后,想要访问都要重启服务器,这样感觉很麻烦的,所以今天就教大家一个方法,只需要 ...

  6. mysql 删匿名帐户

    mysql默认安装,带有匿名帐户 删除它很简单 登录进入msyql并执行以下三行语句: use mysql; delete from user where user=''; flush privile ...

  7. Could note find result map com.xxxx.entity.UserAccountDO

    原因: insert语句的标签写错:应该是parameterType,而不应该是resultType

  8. eclipse open call hierarchy无效

    问题: Eclipse中选中一个方法,右击选中open call hierarchy,不显示哪些地方调用了这个方法,却显示了这个方法里面调用了那些方法.前阵子还是好的,现在不知道为什么了. 解决: s ...

  9. Centos6.5离线安装lsb_release

    参考 http://www.linuxfromscratch.org/blfs/view/systemd/postlfs/lsb-release.html首先在其他电脑下载lsb_release源码地 ...

  10. 洛谷 [P1154] 奶牛分厩

    类似筛法的思想 本题实际上就是反推hash的模数, 首先想到枚举k,但显然会超时. $a mod k==b mod k <==> k|(a-b) $ 由同余的定义可以知道 所以我们的任务就 ...