输入整型数组和排序标识,对其元素按照升序或降序进行排序#
输入整型数组和排序标识,对其元素按照升序或降序进行排序
https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309
n=int(input()) # 必须有int()函数,否则报错
series=input()
sort_direction=int(input()) # 必须有int()函数,否则报错
l=[int(i) for i in series.split()]
if sort_direction==0:
l.sort()
l_str=map(str,l)
print(' '.join(l_str))
elif sort_direction==1:
l.sort(reverse=True)
l_str=map(str,l)
print(' '.join(l_str))

查看20道真题和解析