#include <iostream>
#include <algorithm>
using namespace std;
struct student {
string name,ID;
int grade;
};
int N;
student s[200];
bool comp(student x, student y)
{
return x.grade > y.grade;
}
int main()
{
int i;
cin >> N;
for(i=0;i<N;i++){
cin>>s[i].name>>s[i].ID>>s[i].grade;
}
int g1, g2;
cin >> g1 >> g2;
sort(s, s+N, comp);
int count = 0;
for(i=0; i<N; i++){
if(s[i].grade >= g1 && s[i].grade<= g2){
cout<<s[i].name<<' '<<s[i].ID<<endl;
count++;
}
}
if(!count){
cout << "NONE";
}
}
该程序读取N个学生的信息(姓名、学号、成绩),使用C++标准库中的algorithm对成绩进行降序排序。然后,它在排序后的列表中查找成绩在g1和g2之间(包含边界)的学生,并打印他们的姓名和学号。如果找不到匹配的学生,则输出NONE。

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



