Input:
rhdt:246, ghftd:1246
Output:
trhd, ftdgh
Explanation:
Here, every string (rhdt : 1246) is associated with a
number, separated by semicolon, if sum of square of digit is even the rotate
the string right by 1 position. If square of digit is odd the rotate the string
left by 2 position.
For first case:
2*2+4*4+6*6=84 which is even so rotate string, rotate right
by 1 so ”rhdt” will be “trhd”
For second case:
1*1+2*2+4*4+6*6=85 which is odd so rotate string left by 2
so “ghftd” will be “ftdgh”
a = list(input().split(','))
ReplyDeletels = []
for i in a:
sum = 0
c=''
b = list(i.split(':'))
d=''
for j in b[1]:
if j.strip():
sum+=int(j)**int(j)
if(sum%2==0):
c+= b[0]
d+=c[len(c)-1]
d+=c[0:len(c)-1]
ls.append(d)
else:
c += b[0]
d+=c[len(c) - 3:]
d+= c[0:len(c) - 3]
ls.append(d)
for i in range(len(ls)-1):
print(ls[i],end=',')
print(ls[len(ls)-1])