Header Ad

HackerEarth Palindromic Ciphers problem solution

In this HackerEarth Palindromic Ciphers problem solution Julius Cipher is a type of cipher which relates all the lowercase alphabets to their numerical position in the alphabet, i.e., the value of a is 1, the value of b is 2, the value of z is 26, and similarly for the rest of them.

Little Chandan is obsessed with this Cipher and he keeps converting every single string he gets, to the final value one gets after the multiplication of the Julius Cipher values of a string. Arjit is fed up with Chandan's silly activities, so he decides to at least restrict Chandan's bad habits.

So, he asks Chandan not to touch any string which is a palindrome, otherwise, he is allowed to find the product of the Julius Cipher values of the string.


HackerEarth Palindromic Ciphers problem solution


HackerEarth Palindromic Ciphers problem solution.

x = "abcdefghijklmnopqrstuvwxyz"
y = list(x)
tc = int(raw_input())
while tc>0:
tc = tc - 1
s = raw_input()
if s==s[::-1]:
print "Palindrome"
else:
ans = 1
for i in s:
ans = ans * (y.index(i)+1)
print ans

Post a Comment

0 Comments