题解 | 成绩排序

成绩排序

https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b

n = int(input())
op = int(input())

score_list = []
for i in range(n):
    score_list.append(input().split())

if op == 0:    # 按要求排序
    new_list = sorted(score_list, key=lambda x: int(x[1]), reverse=True)
elif op == 1:
    new_list = sorted(score_list, key=lambda x: int(x[1]))

for i in range(n):
    print(f'{new_list[i][0]} {int(new_list[i][1])}')

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务