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的异常。
________________________________________________________________
需要使用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
相关文章推荐
- CodeForces 731A 之 Night at the Museum
- python codeforces 322 div2 C
- codeforces 151A【python】
- CodeForces 731A - Night at the Museum(模拟)
- Python解决codeforces ---- 7
- CodeForces 731A Night at the Museum (水题)
- python中的eval()+codeforces--116A.Tram
- Python解决codeforces ---- 3
- CodeForces 731A-Night at the Museum
- codeforces 560A【python】
- Python解决codeforces ---- 4
- Python解决codeforces ---- 6
- 【Codeforces Round #376 (Div. 2)】 Codeforces 731A Night at the Museum
- 题解-python-CodeForces 1A
- codeforces 570A【python】
- Codeforces 731A
- codeforces 675 A~E(Round #353 Div. 2) python and C++ 解法
- Python解决codeforces ---- 1
- codeforces 719A 【python】
- CodeForces - 731A 简单题