Python题解 | #成绩排序#

成绩排序

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

import sys

while True:
    try:
        n = int(input())
        key = False if int(input()) else True
        dp = []
        for i in range(n):
            a, b = map(str, input().strip().split())
            dp.append((a, int(b)))
        res = sorted(dp, key=lambda x: x[1], reverse=key)
        for i in res:
            print(i[0], i[1])
    except:
        break

全部评论
注意输入时第一个为字符串第二个为数字要用int 注意dp不能是字典,因为如果key一样则数据就会被最后一组相同key的覆盖掉
点赞 回复 分享
发布于 2024-05-15 22:35 上海

相关推荐

09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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