题解 | #成绩排序#

成绩排序

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

while True:
    try:
        num = int(input())
        flag = int(input())
        scoreKeyDict = {}
        for i in range(num):
            info = input().split()
            keys = int(info[1])
            if keys in scoreKeyDict:
                scoreKeyDict[keys].append(info[0])
            else:
                scoreKeyDict[keys] = []
                scoreKeyDict[keys].append(info[0])
        for i in range(len(scoreKeyDict)):
            if flag:
                a = min(scoreKeyDict.keys())
                b = scoreKeyDict.pop(a)
                for i in b:
                    print('%s %d' % (i, a))
            else:
                a = max(scoreKeyDict.keys())
                b = scoreKeyDict.pop(a)
                for i in b:
                    print('%s %d'%(i,a))
    except:
        break

全部评论

相关推荐

想润的芹菜人狠话不多:把其中一个老总放中间都会得罪另一个
点赞 评论 收藏
分享
HNU_fsq:建议直接出国,这简历太6了。自愧不如
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务