学生成绩处理(二)
描述
已知有5个学生,学生信息由姓名(姓名由大小写字母构成,且长度不超过15) 和3门课的成绩(C语言、英语和数学)构成,求出每个学生的总成绩,并按总成绩降序排序后输出。
输入
输入以空格隔开的5个学生的信息。
输出
输出5个学生的信息,并按总成绩降序排序。 输出时每个数据之间有一个空格,成绩均保留1位小数。
输入样例 1
Zhangfen 93 91 89 Qiudong 60.5 72 75 Ningqiu 50 60.5 63 Baoshi 85 91.5 50 Yulu 80 81 82.5
输出样例 1
Zhangfen 93.0 91.0 89.0 273.0 Yulu 80.0 81.0 82.5 243.5 Baoshi 85.0 91.5 50.0 226.5 Qiudong 60.5 72.0 75.0 207.5 Ningqiu 50.0 60.5 63.0 173.5
提示
HINT 时间限制:200ms 内存限制:64MB
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
struct Student {
std::string name;
double c, english, math, total;
};
bool compare(const Student &a, const Student &b) {
return a.total > b.total;
}
int main() {
std::vector<Student> students(5);
for (int i = 0; i < 5; ++i) {
std::cin >> students[i].name >> students[i].c >> students[i].english >> students[i].math;
students[i].total = students[i].c + students[i].english + students[i].math;
}
std::sort(students.begin(), students.end(), compare);
for (const auto& s : students) {
std::cout << s.name << " " << std::fixed << std::setprecision(1)
<< s.c << " " << s.english << " " << s.math << " " << s.total << std::endl;
}
return 0;
}
7889

被折叠的 条评论
为什么被折叠?



