Problem Statement:
Julius Cipher is a type of cipher which relates all the lowercase alphabets to their numerical position in the alphabet, i.e., value of a is 1, value of b is 2, 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 of 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.
Input:
The first line contains t number of test cases. The first line of every test case contains a string, S.
The first line contains t number of test cases. The first line of every test case contains a string, S.
Output:
Print the value if the string is not a palindrome, otherwise print Palindrome - where value is equal to the product of all the characters of Julius Cipher values.
Print the value if the string is not a palindrome, otherwise print Palindrome - where value is equal to the product of all the characters of Julius Cipher values.
Constraints: 1 <= T <= 102
1<=length of the string<=10
1<=length of the string<=10
Note:
The string will contain only lowercase letters.
The string will contain only lowercase letters.
Programming using python 2.7.6:
The approach for this problem is pretty straight forward. All you need to do is that first check if the input string is palindrome or not. If Palindrome then just print "Palindrome". Else get value of each alphabet from given input string and multiply with next alphabet corresponding value.
Code in Python 2.7:
smallalphabets
= 'abcdefghijklmnopqrstuvwxyz'
EachAlphaValue
= list(enumerate(smallalphabets,1)) # For each alphabet assign
numerical value and store the result in list _
#_
Example: EachAlphaValue = [(1,'a'),.....,(26,'z')]
def getNumvalue(schar,listtupleValue):
for i in
range(len(listtupleValue)):
if listtupleValue[i][1] == schar:
return listtupleValue[i][0]
elif i == len(listtupleValue)-1:
return -1
NumberOfTestCases
= int(raw_input())
OutputResult
=[]
while NumberOfTestCases:
userinput = raw_input()
CipherValue = 1
if userinput[::-1] == userinput:
OutputResult.append('Palindrome')
else:
for k in userinput:
if getNumvalue(k, EachAlphaValue) != -1:
#print
getNumvalue(k, EachAlphaValue)
CipherValue = CipherValue *
getNumvalue(k, EachAlphaValue)
else:
CipherValue = -1
OutputResult.append(CipherValue)
NumberOfTestCases -=1
for output in OutputResult : print output
No comments:
Post a Comment