#!/usr/bin/python3 # # this program reads a list of numbers from the standard input, with # one or more numbers per line separated by spaces on each line, and # prints the largest cluster of extension D. The parameter D is a # number that may be given as the first command-line argument. If the # parameter is not specified, the default value is D=10. A cluster of # extension D is a list of all the elements taken from the input list # that are within a distance of at most D from each other. For # example, if the input sequence is 12, 2, 34, 7, 21, 24, 50, 45, -9, # 7, 45, and if D=10, then the output should contain the numbers 12, # 2, 7, 7 because those numbers form a cluster of extension 10, and no # other cluster of extension 10 contains more than 4 elements. # import sys A = [] for l in sys.stdin: for n in l.split(' '): A.append(int(n.strip())) try: D = int(sys.argv[1]) except: D = 10 max_c = [] for a in A: c = [] for b in A: if b >= a and b - a <= D: c.append(b) if len(c) > len(max_c): max_c = c for x in max_c: print(x, end=' ') print()