Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 输入学生人数
- n = int(input("请输入学生人数 n: "))
- students = []
- # 输入学生信息
- print(f"请输入 {n} 行学生信息,格式为:名字 语文 数学 英语:")
- for _ in range(n):
- info = input().split()
- name = info[0]
- scores = list(map(int, info[1:]))
- total_score = sum(scores)
- students.append((name, scores, total_score))
- # 排序函数
- def custom_sort(student):
- name, scores, total_score = student
- return (-total_score, -scores[0], -scores[1], -scores[2])
- # 按照总分排序
- sorted_students = sorted(students, key=custom_sort)
- # 输出排序后的学生信息
- print("排序后的学生信息:")
- for student in sorted_students:
- print(f"{student[0]} {student[2]}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement