给定N个学生的基本信息,包括学号(由12个数字组成的字符串)、姓名(长度小于20的不包含空白字符的非空字符串)、高等数学成绩、C语言程序设计成绩,成绩均为[0,100]区间内的整数,要求根据C语言的成绩,对学生名单进行降序排列。 输入格式: 输入在一行中给出正整数N(≤10)。随后N行,每行给出一位学生的信息,格式为“学号 姓名 高等数学成绩 C语言程序设计成绩”,中间以空格分隔。 输出格式: 按照C语言课程程序降序,输出所有学生信息,一行是一个学生的信息,信息之间用空格隔开。
时间: 2024-02-29 08:56:58 浏览: 26
好的,这是一个简单的排序问题,我们可以使用结构体来存储每个学生的信息,并使用快速排序算法对学生信息进行排序。以下是示例代码:
```c++
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 10;
struct Student{
string id;
string name;
int math;
int c;
int sum;
}stu[N];
bool cmp(Student a, Student b){
return a.c > b.c;
}
int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++){
cin >> stu[i].id >> stu[i].name >> stu[i].math >> stu[i].c;
stu[i].sum = stu[i].math + stu[i].c;
}
sort(stu, stu+n, cmp);
for(int i = 0; i < n; i++){
cout << stu[i].id << " " << stu[i].name << " " << stu[i].math << " " << stu[i].c << endl;
}
return 0;
}
```
我们首先定义了一个结构体 `Student`,用来存储每个学生的信息。在 `main` 函数中,我们首先输入每个学生的信息,并计算出每个学生的总分数。然后我们使用 `sort` 函数进行排序,排序规则是按照 C 语言成绩降序排列。最后输出排序后的学生信息即可。
这个程序可以满足你的要求吗?