题解 | 最厉害的学生

最厉害的学生

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

全部评论

相关推荐

10-15 10:23
门头沟学院 Java
牛可乐的头像真牛:赶紧举报,这公司绝对是诈骗的,等你签约后工作一两个月后根据合同漏洞把你开除,并且要求你赔偿3w培训费,996是为了提前筛选心甘情愿签下合同容易受骗的群体,纯粹面向校招生精心设计的骗局
你见过哪些工贼行为
点赞 评论 收藏
分享
11-17 23:00
南昌大学 Java
我要娶个什么名:10元一天 0元提成😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务