您的位置:首页 > 编程语言 > Python开发

codeforces 731A【python】

2017-10-25 22:33 393 查看
需要考虑顺时针与逆时针转换的数字大小,并要在输入的string前加上"a"

________________________________________________________________

需要使用python的ord函数——

ord()函数是chr()函数(对于8位的ASCII字符串)或unichr()函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数,返回对应的ASCII数值,或者Unicode数值,如果所给的Unicode字符超出了你的Python定义范围,则会引发一个TypeError的异常。

line = raw_input()
line = "a" + line
real_distance = 0
total_distance = 0

for i in range(1,len(line)):
distance1 = abs(ord(line[i]) - ord(line[i-1]))
distance2 = 26 - distance1
if distance1 < distance2:
real_distance = distance1
else:
real_distance = distance2

total_distance += real_distance

print total_distance
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python codeforces