PAT 甲级 1083 List Grades
简单的排序题
#include<bits/stdc++.h>
using namespace std;
struct Student
{
string name_;
string id_;
int scores_;
};
bool cmp(const Student &lhs, const Student &rhs)
{
return lhs.scores_ > rhs.scores_;
}
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n; cin >> n;
vector<Student> student_set(n);
for (int i = 0; i < n; ++i) {
cin >> student_set[i].name_ >> student_set[i].id_ >> student_set[i].scores_;
}
int left_scores, right_scores; cin >> left_scores >> right_scores;
sort(student_set.begin(), student_set.end(), cmp);
bool have_printed = false;
for (auto &i : student_set) {
if (i.scores_ >= left_scores && i.scores_ <= right_scores) {
cout << i.name_ << " " << i.id_ << endl;
have_printed = true;
}
}
if (!have_printed) cout << "NONE" << endl;
}