Friend and Enemy
A group of F friends went to a haunted house.Each member was given a shirt with a number on it ranging from 1 to F. As they entered the haunted house, one of them was kidnapped and an enemy joined them.But unfortunately, the enemy didn't wear the shirt with the same number as the kidnapped one, instead wore the same as some other person.Find the numbers on the shirts of the enemy and the kidnapped person.
Input
The input is a single line containing space-separated positive integers from 1 to F.
Output
The output should be a single line containing the shirt numbers of the enemy and kidnapped person separated by a space.
Explanation
The given array is 3 1 5 2 1.
In the range from 1 to 5, the number 1 has occured twice and 4 is the missing number. So, 1 belongs to the enemy's shirt, and 4 belongs to kidnapped.Hence, the output should be 1 4.
Sample Input1
3 1 5 2 1
Sample Output1
1 4
Sample Input2
1 2 2 4
Sample Output2
2 3
line = input()
L = [int(w) for w in line.split()]
F = len(L)
digits = [0]*F
for d in L:
digits[d-1] += 1
for i in range(F):
if digits[i] == 0:
kidnapped = i + 1
if digits[i] == 2:
enemy = i + 1
print(enemy, kidnapped)
Comments
Leave a comment