找出数组中的所有最小差数字对
代码如下
arr = input("")
num = [int(n) for n in arr.split()]#输入数组,以空格为间隔
num.sort()#排序
min = num[-1] - num[0]
for i in range(1,len(num)):
if num[i] - num[i-1] < min:
min = num[i] - num[i-1]#找出最小差
for i in range(1,len(num)):
if num[i] -num[i-1] == min:
print("(",num[i-1],num[i],")")#输出所有是最小差的数字对