Digital encryption PAT 1048 (20 minutes) (python 3)

This problem required to achieve a digital encryption method. First, encrypted with a fixed positive integer A, for any positive integer B, and the numbers on each of positions corresponding to 1-bit digital to A following operation: After an odd bit, the corresponding bit of the digital sum modulo 13 - - 10 used here representative of J, representative of Q 11, K 12 represents; on even bit, with the number B minus the number of a, if the result is negative, then add 10. Here a bit to make the first one.
Input format:
input sequence is given in row A and B, no more than 100 are positive integers, separated by a space therebetween.
Output format:
the result of the encrypted output in a row.
Sample input:
1,234,567,368,782,971
Output Sample:
3695Q8118

Code

A,B=input().split()
max=max(len(A),len(B))
A=A.zfill(max)
B=B.zfill(max)
lA=list(A)
lA.reverse()
lB=list(B)
lB.reverse()
sum=[]
x=['J','Q','K']
min=min(len(lA),len(lB))
for i in range(min):
    if (i+1)%2==1:
        a=(int(lA[i])+int(lB[i]))%13
        if a>=10:
            a=x[a%10]
    else:
        a=int(lB[i])-int(lA[i])
        if a<0:
            a+=10
    sum.append(str(a))
sum.reverse()
print("".join(sum))
Published 23 original articles · won praise 0 · Views 347

Guess you like

Origin blog.csdn.net/qq_46258819/article/details/104819279