We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Yeah exactly just subtract the ascii values of the reverse string and normal string and take the absolute value of it and then divide by 2.
The code is given below:-
t=int(input())
for i in range (t):
s=list(input())
rev=s[::-1]
changes=0
for i in range (len(s)):
changes+=abs(ord(rev[i])-ord(s[i]))
print(changes//2)
The Love-Letter Mystery
You are viewing a single comment's thread. Return to all comments →
Yeah exactly just subtract the ascii values of the reverse string and normal string and take the absolute value of it and then divide by 2. The code is given below:-
t=int(input()) for i in range (t): s=list(input()) rev=s[::-1] changes=0 for i in range (len(s)): changes+=abs(ord(rev[i])-ord(s[i])) print(changes//2)