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 ...
随机推荐
- 新鲜博客出炉www.pubwin2009.net
既然不快乐,又不喜欢这里,不如一路向西去大理.不是说不喜欢博客园,而是不喜欢现在工作的公司已经向公司递了辞职申请,然后突然有个想把,就是把公司里学到的东西做一个总结,全部写下来正好阿里云可以有免费半年 ...
- CSAPP--优化程序性能
一.编写高效的程序: 1.选择合适的算法和数据结构. 2.编写出编译器能够有效优化以转换为高效可执行的源代码. 3.并行计算.当然重点还是第一个,良好的算法和数据结构大大减小了程序的时间复杂度. 二. ...
- 如何监听input的脚本赋值
今天记录下我解决input值改变监听,大家肯定首先想到onchange方法.对于实时监听改变用onpropertychange.oninput等方法:可是,onchange并不能监听脚本改变的值,对于 ...
- write a macro to judge big endian or little endian
Big endian means the most significant byte stores first in memory. int a=0x01020304, if the cpu is b ...
- FJ省队集训DAY4 T1
直接上题解 #include<cstdio> #include<iostream> #include<cmath> #include<cstring> ...
- ASP.ENT中上一篇和下一篇
前台页面:<div class="mtgz_prev_next"> <p> <span class="textcolor ...
- Builder模式的几个要点
1.Builder模式主要用于“分步骤构建一个复杂的对象”.在这其中“分步骤”是一个稳定的算法,而复杂对象的各个部分则经常变化.2.变化点在哪里,封装哪里——Builder模式主要在于应对“复杂对象各 ...
- 转:linux执行shell脚本的方式及一些区别
假设shell脚本文件为hello.sh放在/root目录下.下面介绍几种在终端执行shell脚本的方法: [root@localhost home]# cd /root/ [root@localho ...
- bzoj1003[ZJOI2006]物流运输trans
1003: [ZJOI2006]物流运输trans Description 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常 ...
- poj 2046 Gap(bfs+hash)
Description Let's play a card game called Gap. You have cards labeled with two-digit numbers. The fi ...