题解 | 最厉害的学生

最厉害的学生

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

全部评论

相关推荐

嵌入式的小白:简历关键的就是项目经历,你这密密麻麻的,我一点开就不想看了,每一条都不换行,而且每一个里面写那么多,需要精简一下,这样别人看一眼就能知道你做了啥,用了啥技术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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