地址:
https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309?tpId=37&tqId=21324&rp=1&ru=%2Fta%2Fhuawei&qru=%2Fta%2Fhuawei%2Fquestion-ranking&tab=answerKey
1 ''' 2 3 題目描述 4 輸入整型數組和排序標識,對其元素按照升序或降序進行排序(一組測試用例可能會有多組數據) 5 6 本題有多組輸入,請使用while(cin>>)處理 7 8 輸入描述: 9 第一行輸入數組元素個數 10 第二行輸入待排序的數組,每個數用空格隔開 11 第三行輸入一個整數0或1。0代表升序排序,1代表降序排序 12 13 輸出描述: 14 輸出排好序的數字 15 16 示例1 17 輸入 18 8 19 1 2 4 9 3 55 64 25 20 0 21 5 22 1 2 3 4 5 23 1 24 輸出 25 1 2 3 4 9 25 55 64 26 5 4 3 2 1 27 28 ''' 29 30 while True: 31 try: 32 n = int(input()) 33 except: 34 break 35 l = input().split() 36 sor = int(input()) 37 rev = True if sor ==1 else False 38 l.sort(key=lambda i:int(i),reverse=rev) 39 res = '' 40 for i in l: 41 res += i +' ' 42 print(res)