先用split将字符串以空格为标志间隔开,再用冒泡排序法将列表排序,排完序后再将列表转化为以空格隔开的字符串
n = int(input())
str_n = input().split()
k = int(input())
str_l = list(str_n)
for i in range(0,len(str_l)):
for j in range(i,len(str_l)):
if k == 0 :
if int(str_l[i]) > int(str_l[j]):
t = str_l[i]
str_l[i] = str_l[j]
str_l[j] = t
elif k == 1:
if int(str_l[i]) < int(str_l[j]):
t = str_l[i]
str_l[i] = str_l[j]
str_l[j] = t
print(' '.join(str_l))