The Love-Letter Mystery
def numOperations(testStr):
num = 0
n = len(testStr)
for i in range(n / 2):
num += abs(ord(testStr[i]) - ord(testStr[n - i - 1]))
return num def main():
t = int(raw_input())
for _ in range(t):
testStr = raw_input().strip()
print numOperations(testStr) main()
Link:
https://www.hackerrank.com/challenges/the-love-letter-mystery
学习
利用Asckii码来解决问题
strip()去除结尾
错误
一定注意数组和list的下标,这个是很容易出错的坑
The Love-Letter Mystery的更多相关文章
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- 什么是Unicode letter
起因:从一段代码说起 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- LeetCode——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- No.017:Letter Combinations of a Phone Number
问题: Given a digit string, return all possible letter combinations that the number could represent.A ...
- SCI/EI期刊投稿 Reply Letter 常用格式总结
SCI/EI期刊投稿Reply Letter常用格式总结 整个论文投稿的过程中,会遇到各种问题,需要我们向主编询问或是回复.下面主要总结了responses to the comme ...
- 【leetcode】 Letter Combinations of a Phone Number(middle)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- [LeetCode] Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- [LintCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 69. Letter Combinations of a Phone Number
Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...
随机推荐
- Codeforces 56D Changing a String
http://codeforces.com/contest/56/problem/D 题目大意: 一个字符串变为目标字符串,可以执行插入,置换和删除3种操作,求最少操作数. 思路:dp[i][j]代表 ...
- Could not find *.apk!解决办法
右键点击项目选择Properties,把Libraries下Android x.x给remove了. 点右侧的Add Library,选择JRE System Library然后next,重新指定JR ...
- pmp论坛
PMP论坛: http://www.px101.com/specialpmp/ http://www.pmp.cn/ http://www.pmptuan.com/ http://www.mypm.n ...
- 【转】Android API 中文(14) —— ViewStub
用一个XML源填充view.inflate(上下文对象,资源文件Id,父窗口组一般为null): 原文网址:http://www.cnblogs.com/over140/archive/2010/10 ...
- fstream读写UNICODE文件
今天遇到要处理UNICODE文件的情况,网上找了一圈都是读取出字节,再转的,这个不方便啊!想起了有codecvt这么个东西,顺藤摸瓜,找到了方法. locale utf16(locale(" ...
- puppet cert maintain
- Bugscan学习笔记------关于urlparse
urlparse模块主要是把url拆分为6部分,并返回元组.并且可以把拆分后的部分再组成一个url.主要有函数有urljoin.urlsplit.urlunsplit.urlparse等. ***** ...
- CSS介绍
从HTML被发明开始,样式就以各种形式存在.不同的浏览器结合它们各自的样式语言为用户提供页面效果的控制.最初的HTML只包含很少的显示属性. 随着HTML的成长,为了满足页面设计者的要求,HTML添加 ...
- android 银行卡。。空格输入
class myWatcher implements TextWatcher { int beforeTextLength = 0; int onTextLength = 0; boolean isC ...
- C++11多线程教学II
从我最近发布的C++11线程教学文章里,我们已经知道C++11线程写法与POSIX的pthreads写法相比,更为简洁.只需很少几个简单概念,我们就能搭建相当复杂的处理图片程序,但是我们回避了线程同步 ...