输入格式: 在一行中输入一个班的学生成绩(成绩可以包含一位小数),中间用空格分隔。 输出格式: 打印班级平均分(保留1位小数),以及以及高于平均分的学生成绩。(最后一个成绩后有一个空格)
时间: 2024-05-14 07:19:09 浏览: 26
以下是Python的代码实现:
```python
scores = input().split() # 输入学生成绩,以空格分隔
scores = list(map(float, scores)) # 转换成浮点数列表
average = sum(scores) / len(scores) # 计算平均分
above_average = [score for score in scores if score > average] # 找出高于平均分的成绩
print("{:.1f} ".format(average), end='') # 输出平均分,保留1位小数
for score in above_average:
print("{:.1f} ".format(score), end='') # 输出高于平均分的成绩,保留1位小数
```
示例输入:
```
90.5 88.0 93.0 76.5 85.0
```
示例输出:
```
86.6 90.5 88.0 93.0 85.0
```
相关问题
已知学生的信息包括姓名、成绩。编写程序从键盘输入5个学生的信息,输出其中成绩最高者的姓名和成绩。 输入格式: 每条信息占一行,姓名和成绩之间用空格分隔。 输出格式: 输出成绩保留1位小数。
好的,这是一个简单的程序设计问题,下面是实现这个程序的 Python 代码:
```python
# 定义一个存储学生信息的列表
students = []
# 从键盘输入5个学生的信息,存储到列表中
for i in range(5):
name, score = input().split()
students.append({'name': name, 'score': float(score)})
# 找出成绩最高的学生
max_score = 0
max_name = ''
for student in students:
if student['score'] > max_score:
max_score = student['score']
max_name = student['name']
# 输出成绩最高的学生的姓名和成绩
print('{0} {1:.1f}'.format(max_name, max_score))
```
你可以复制以上代码到 Python 环境中运行,然后输入每个学生的信息,程序会输出成绩最高的学生的姓名和成绩。
已知学生的信息包括姓名、成绩。编写程序从键盘输入5个学生的信息,输出其中成绩最高者的姓名和成绩。 输入格式: 每条信息占一行,姓名和成绩之间用空格分隔。 输出格式: 输出成绩保留1位小数。使用c++解决
好的,这里是使用 C++ 实现的代码:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Student {
string name;
double score;
bool operator<(const Student& other) const {
return score < other.score;
}
};
int main() {
vector<Student> students;
// 从键盘输入5个学生的信息,存储到vector中
for (int i = 0; i < 5; ++i) {
string name;
double score;
cin >> name >> score;
students.push_back({name, score});
}
// 找出成绩最高的学生
auto maxIt = max_element(students.begin(), students.end());
cout << maxIt->name << " " << fixed << setprecision(1) << maxIt->score << endl;
return 0;
}
```
你可以复制以上代码到 C++ 环境中运行,然后输入每个学生的信息,程序会输出成绩最高的学生的姓名和成绩。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)