题解 | #成绩排序# 打了顺序标志 感觉直接用i -i也行
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
n = int(input()) flag = int(input()) # 1递增+0.0001 0递减 -0.0001 delta = 0.0001 if flag == 1 else -0.0001 students = [] for i in range(n): name, grade = input().split() grade = int(grade) signal = grade + i*delta students.append([name,grade,signal]) students.sort(key= lambda x:(x[1],x[2]), reverse=not flag) for st in students: print("{} {}".format(st[0],st[1]))