输入在第一行给出正整数N(N<=10);随后N行,每行按格式: 学号 姓名 数学成绩 英语成绩 程序设计成绩 物理成绩
时间: 2024-02-04 13:01:54 浏览: 106
设计一个学生类Student(学生学号、姓名、数学、英语、计算机成绩;)
5星 · 资源好评率100%
以下是Python实现的代码:
```python
N = int(input())
students = []
# 读入学生信息
for i in range(N):
info = input().split()
student = {
'id': info[0],
'name': info[1],
'math': int(info[2]),
'english': int(info[3]),
'programming': int(info[4]),
'physics': int(info[5])
}
students.append(student)
# 计算每个学生的总成绩和平均成绩
for student in students:
total_score = student['math'] + student['english'] + student['programming'] + student['physics']
average_score = total_score / 4
student['total_score'] = total_score
student['average_score'] = average_score
# 按照总成绩从高到低排序
students.sort(key=lambda x: x['total_score'], reverse=True)
# 输出学生信息
for student in students:
print('{} {} {:.2f}'.format(student['id'], student['name'], student['total_score']))
```
输入样例:
```
3
1001 Tom 90 80 85 95
1002 Jerry 85 90 92 88
1003 Bob 78 85 80 90
```
输出样例:
```
1001 Tom 350.00
1002 Jerry 355.00
1003 Bob 333.00
```
阅读全文