题解 | 最厉害的学生
最厉害的学生
https://www.nowcoder.com/practice/b6e7a9ca04d8418b805b3b4b7d25b4d4
class Student:
# 学生信息
def __init__(self, name, chinese, math, english, no):
self.name = name
self.chinese = chinese
self.math = math
self.english = english
self.no = no
self.feng = self.chinese + self.math + self.english
n = int(input())
stu = []
for i in range(n):
e = input().split()
name, chinese, math, english = e[0], int(e[1]), int(e[2]), int(e[3])
stu.append(Student(name, chinese, math, english, i))
# 关键就是2个关键字排序的问题
sorted_stu = sorted(stu, key=lambda xue: (xue.feng, xue.no))
# print('"""""""""""""""""""""')
# for xue in sorted_stu:
# print(xue.name,xue.chinese,xue.math,xue.english,xue.feng,xue.no)
# print("____________________________________________")
zuida = sorted_stu[n - 1].feng
# print(sorted_stu[n-1].no,zuida)
# print("***********************")
for i in range(n):
if sorted_stu[i].feng == zuida:
print(
sorted_stu[i].name,
sorted_stu[i].chinese,
sorted_stu[i].math,
sorted_stu[i].english,
)
break
查看13道真题和解析