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的下标,这个是很容易出错的坑