The Love-Letter Mystery

 1 def numOperations(testStr):

 2     num = 0

 3     n = len(testStr)

 4     for i in range(n / 2):

 5         num += abs(ord(testStr[i]) - ord(testStr[n - i - 1]))

 6     return num

 7 

 8 

 9 def main():

10     t = int(raw_input())

11     for _ in range(t):

12         testStr = raw_input().strip()

13         print numOperations(testStr)

14 

15 

16 main()

Link:

  https://www.hackerrank.com/challenges/the-love-letter-mystery

学习

  利用Asckii码来解决问题

  strip()去除结尾

错误

  一定注意数组和list的下标,这个是很容易出错的坑

 

你可能感兴趣的:(love)