对输入进行筛选,选取在范围内的学生数据,然后对筛选的数据进行排序输出就好了
#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;struct node{ string name; string id; int grade; bool Operator<(const node that) const { return grade > that.grade; }};vector<node> all;//保存输出vector<node> re;//存储结果输出int main(){ int N; cin >> N; all.resize(N); for (int t = 0;t < N;t++) cin >> all[t].name >> all[t].id >> all[t].grade; int m, M; cin >> m >> M; for (auto x : all) if (x.grade >= m&&x.grade <= M) re.push_back(x); sort(re.begin(), re.end()); if (re.empty()) cout << "NONE" << endl; else for (auto x : re) cout << x.name << " " << x.id << endl;}新闻热点
疑难解答