Advertisement
wyx0311

电宇智控视觉组1_3

May 15th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | Source Code | 0 0
  1. # 输入学生人数
  2. n = int(input("请输入学生人数 n: "))
  3.  
  4. students = []
  5.  
  6. # 输入学生信息
  7. print(f"请输入 {n} 行学生信息,格式为:名字 语文 数学 英语:")
  8. for _ in range(n):
  9.     info = input().split()
  10.     name = info[0]
  11.     scores = list(map(int, info[1:]))
  12.     total_score = sum(scores)
  13.     students.append((name, scores, total_score))
  14.  
  15. # 排序函数
  16. def custom_sort(student):
  17.     name, scores, total_score = student
  18.     return (-total_score, -scores[0], -scores[1], -scores[2])
  19.  
  20. # 按照总分排序
  21. sorted_students = sorted(students, key=custom_sort)
  22.  
  23. # 输出排序后的学生信息
  24. print("排序后的学生信息:")
  25. for student in sorted_students:
  26.     print(f"{student[0]} {student[2]}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement