输入整型数组和排序标识,对其元素按照升序或降序进行排序
数据范围: ,元素大小满足
第一行输入数组元素个数第二行输入待排序的数组,每个数用空格隔开第三行输入一个整数0或1。0代表升序排序,1代表降序排序
输出排好序的数字
8 1 2 4 9 3 55 64 25 0
1 2 3 4 9 25 55 64
5 1 2 3 4 5 1
5 4 3 2 1
n=int(input()) print(*list(sorted(list(map(int,input().split())),reverse=eval(input()))))
while True: try: n,list,sort_way = int(input()),input().split(""),int(input()) new_list = [0 for index in range(n)] count = 0 right_locate = 0 for item in list: item=int(item) # 初始化new_list if count == 0: new_list[0] = item count += 1 continue if sort_way==0: # 找第(count+1)的值的具体索引值 for k in range(count): if item <new_list[k]: #如果比第一个值还小,该值的right_locate就是0 right_locate=0 break if item >= new_list[k] and item <= new_list[k + 1]: #如果比第k个值大,比k+1值小,该值的right_locate就是k+1 right_locate = k + 1 break if k == (count - 1): #如果比到了最后一个值,说明该值就是目前最大的 right_locate = count # 挪位置 if right_locate!=count: for i in range(count - right_locate): new_list[count - i] = new_list[count - i - 1] new_list[right_locate] = item count+=1 else: # 找第(count+1)的值的具体索引值 for k in range(count): if item>new_list[k]: right_locate=0 break if item <= new_list[k] and item >= new_list[k + 1]: right_locate = k + 1 break if k == (count - 1): right_locate = count # 挪位置 if right_locate!=count: for i in range(count - right_locate): new_list[count - i] = new_list[count - i - 1] new_list[right_locate] = item count += 1 result = str() for m in new_list: result += f"{m} " result.strip() print(result) except: break
a = input() a = list(map(int,input().split())) option = int(input()) a.sort() m = "" if option: a.reverse() for i in a: m += str(i) + " " print(m[:-1])
x = int(input()) y = list(map(int, input().split())) z = int(input()) if z == 1: for i in sorted(y, reverse=True): print(i, end=' ') else: for i in sorted(y): print(i, end=' ')
n = int(input()) ipList = list(map(int, input().split())) f = int(input()) if f == 0: ipList = sorted(ipList) else: ipList = sorted(ipList, reverse=True) for item in ipList: print(item, end=' ')
n = int(input()) num_list = input().split() sort_key = int(input()) for i in range(n): num_list[i] = int(num_list[i]) if sort_key == 0: for i in sorted(num_list): print(i,end=' ') elif sort_key == 1: for i in sorted(num_list,reverse = True): print(i,end=' ')
k = int(input("")) arr = input("").split() tag = int(input("")) while True: if tag == 0&nbs***bsp;tag ==1: break else: print("请重新输入tag") tag = int(input("请输入升序0或者降序1:")) arr_len = arr[:k] if tag == 0: for i in range(len(arr) - 1): for j in range(len(arr) - 1 - i): arr[j] = int(arr[j]) arr[j + 1] = int(arr[j + 1]) if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] else: for i in range(len(arr) - 1): for j in range(len(arr) - 1 - i): arr[j] = int(arr[j]) arr[j + 1] = int(arr[j + 1]) if arr[j] < arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] for i in arr: print(i, "", end="")