题解 | #成绩排序#
成绩排序
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