Generate Key - Accenture
Generate Key - Accenture
Problem:
The program must accept three integers X, Y and Z as the input. Each of these are four-digit integers. The program must generate a four-digit key K based on the following conditions. - The 1st digit in K must be equal to the SMALLEST digit in the thousands place of all three integers. - The 2nd digit in K must be equal to the LARGEST digit in the hundreds place of all three integers. - The 3rd digit in K must be equal to the SMALLEST digit in the tens place of all three integers. - The 4th digit in K must be equal to the LARGEST digit in the units place of all three integers.
1000 <= X, Y, Z = 9999
Input:
5107 1234 2948
Output:
1908
Program:
l = list(map(int,input().split()))
k = [9,0,9,0]
ans = 0
for i in l:
k[0] = min(k[0],i//1000)
k[1] = max(k[1],i//100%10)
k[2] = min(k[2],i//10%10)
k[3] = max(k[3],i%10)
for i in k:
ans = ans * 10 + i
print(ans)
Comments
Post a Comment