rosien

Transform the string

Nov 27th, 2021 (edited)
495
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def solve(S , F):
  2.     steps = 0
  3.     for letter in S:
  4.         if abs(ord(letter) - ord(F)) > 13:
  5.             steps += abs(abs(ord(letter) - ord(F)) - 26)
  6.         else:
  7.             steps += abs(ord(letter) - ord(F))
  8.     return steps
  9.  
  10. cases = int(input())
  11. for i in range(cases):
  12.     S, F = input(),  input()
  13.     print('Case #{}: {}'.format( i+1, solve(S, F)))
RAW Paste Data