integers = [int(number) for number in input().split()]
K = int(input())
triplets = []
for i in range(len(integers)):
for j in range(i+1,len(integers)):
for k in range(j+1, len(integers)):
a = integers[i]
b = integers[j]
c = integers[k]
if a+b+c == K:
triplets.append(tuple((a,b,c)))
sorted_triplets=[]
for tripl in triplets:
item = sorted(tripl)
sorted_triplets.append(item)
triplets= sorted(sorted_triplets)
if len(triplets)!=0:
for triplet in triplets:
triplet=sorted(triplet)
tuple_a=tuple(triplet)
print(tuple_a)
input:0 1 2 3 5 7 13 17 19 19
22
output should be like this :
(0, 3, 19)
(0, 5, 17)
(1, 2, 19)
(2, 3, 17)
(2, 7, 13)
integers = [int(number) for number in input().split()]
K = int(input())
triplets = []
for i in range(len(integers)):
for j in range(i+1,len(integers)):
for k in range(j+1, len(integers)):
tmp = tuple(sorted([integers[i], integers[j], integers[k]]))
if sum(tmp) == K:
if tmp not in triplets:
triplets.append(tmp)
triplets_tuple = tuple(sorted(triplets))
print(*triplets_tuple, sep='\n')
Comments
Leave a comment