输出n个整数里最小的k个数

 
 
def qsort(L):#排序
    if len(L) <= 1:return L
    return qsort([lt for lt in L[1:] if lt < L[0]]) + L[0:1]+\
           qsort([ge for ge in L[1:] if ge >= L[0]])
nin=input("n:")
splitn=nin.split(" ")
a=len(splitn)
List=[]
for i in range(a):
    List.append(int(splitn[i]))
nout=qsort(List)
print(nout)
kin=input("k:")
kout=nout[:int(kin)]
print(kout)

输入:3 9 6 8 -10 7 -11 19 30 12 23 5

输出:[-11, -10, 3, 5, 6]



猜你喜欢

转载自blog.csdn.net/zx520113/article/details/80367552
今日推荐