Python 算法:高效实现学生成绩排名
def rank(n, scores): rank_list = sorted(range(n), key=lambda x: (-scores[x], x+1)) return [rank_list.index(i)+1 for i in range(n)]
输入学生人数和分数
n = int(input()) scores = [int(x) for x in input().split()]
计算排名
result = rank(n, scores)
输出每个学生的排名
print(*result)
原文地址: https://www.cveoy.top/t/topic/o6oh 著作权归作者所有。请勿转载和采集!