输入整型数组和排序标识,对其元素按照升序或降序进行排序
数据范围: ,元素大小满足
第一行输入数组元素个数第二行输入待排序的数组,每个数用空格隔开第三行输入一个整数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
input() ls = list(map(int,input().split())) ls.sort(reverse=int(input())) print(' '.join(list(map(str,ls))))
# 1. 接收输入,转数字 ns = input() ls = input() ls_list = ls.split(' ') ls_num_list = [int(x) for x in ls_list] t = input() # 判断范围,可省略 if int(ns) < 1&nbs***bsp;int(ns) > 1000: exit() for item in ls_list: if int(item) < 0&nbs***bsp;int(item) > 100000: exit() # 排序 if t == '0': ls_num_list.sort() elif t == '1': ls_num_list.sort(reverse=True) # 输出 for i in ls_num_list: print(i, end=' ')
input() list_initial = input().split() list_output = [] for i in range(len(list_initial)): list_output.append(int(list_initial[i])) list_output.sort(reverse=int(input())) print(' '.join(list(map(str,list_output))))
# 解法一 while True: try: _ = input() # 输入按空格分隔然后map为整数再转为list s = list(map(int, input().split(" "))) # 布尔型变量判断0/1 flag = bool(int(input())) # 按flag的是否来升序或者降序排列 s = sorted(s, reverse=flag) for i in s: print(i, end=" ") except: break # 解法二 while True: try: _ = input() # 直接分隔 s = input().split(" ") # 布尔型变量判断0/1 flag = bool(int(input())) # 指定类型后,按flag的是否来升序或者降序排列 s = sorted(s, key = int, reverse=flag) for i in s: print(i, end=" ") except: break
num = int(input()) input_str = input() input_array = [int(i) for i in input_str.split(" ")] tag = int(input()) if tag == 0: input_array.sort() else: input_array.sort(reverse=True) out = "" for i in range(len(input_array)): out += str(input_array[i]) if i < len(input_array) - 1: out += " " print(out)
n = int(input()) num = list(map(int,input().split())) a = int(input()) if n in range(1,1001): if a == 0: num.sort() elif a ==1: num.sort(reverse=True) else: print('输入错误') for i in num: print(i,end=' ')
n = int(input()) data = list(map(int,input().split())) k = int(input()) def part(data, l, r): pivot = data[l] while l < r: # 右指针 while l < r and data[r] >= pivot: r -=1 if data[r] < pivot: data[l] = data[r] # 左指针 while l < r and data[l] <= pivot: l += 1 if data[l] > pivot: data[r] = data[l] if l==r: data[l] = pivot mid = l #&nbs***bsp;r return mid def quick_sort(data, l, r): if l > r: return mid = part(data, l, r) quick_sort(data, l, mid-1) quick_sort(data, mid+1, r) # 用快排 quick_sort(data, l=0, r=len(data)-1) if k == 1: # 降序 data = sorted(data,reverse=True) print(' '.join([str(i) for i in data]))
n = int(input()) ls = input().split() r = int(input()) ls = sorted(map(int,ls),reverse=bool(r)) print(" ".join(map(str,ls)))
a = input() b = input() c = input() d = b.split(' ') d1 = [] for i in d: d1.append(int(i)) if c == '0': e = sorted(d1, reverse=False) else: e = sorted(d1, reverse=True) ee = '' for i in e: # print(str(i)) ee = ee + str(i) + ' ' print(ee)