PAT 甲级 1062 Talent and Virtue
#include<bits/stdc++.h>
using namespace std;
struct People
{
string ID_number_;
int virtue_grade_{ -1 };
int talent_grade_{ -1 };
int type_{ -1 };
};
bool cmp(const People &lhs, const People &rhs)
{
if (lhs.type_ != rhs.type_)
return lhs.type_ > rhs.type_;
else if ((lhs.virtue_grade_ + lhs.talent_grade_) != (rhs.virtue_grade_ + rhs.talent_grade_))
return (lhs.virtue_grade_ + lhs.talent_grade_) > (rhs.virtue_grade_ + rhs.talent_grade_);
else if (lhs.virtue_grade_ != rhs.virtue_grade_)
return lhs.virtue_grade_ > rhs.virtue_grade_;
else
return lhs.ID_number_ < rhs.ID_number_;
}
int main()
{
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int total_number_to_rank, lower_bound_grade, high_bound_grade;
cin >> total_number_to_rank >> lower_bound_grade >> high_bound_grade;
int ranked_ctr = 0; vector<People> ranked_set;
string ID_number; int virtue_grade, talent_grade, type;
while (total_number_to_rank--) {
cin >> ID_number >> virtue_grade >> talent_grade;
if (virtue_grade >= lower_bound_grade && talent_grade >= lower_bound_grade) {
if (virtue_grade >= high_bound_grade && talent_grade >= high_bound_grade) type = 3;
else if (virtue_grade >= high_bound_grade && talent_grade < high_bound_grade) type = 2;
else if (virtue_grade >= talent_grade) type = 1;
else type = 0;
ranked_set.push_back({ ID_number,virtue_grade,talent_grade,type });
++ranked_ctr;
}
}
sort(ranked_set.begin(), ranked_set.end(), cmp);
cout << ranked_ctr << endl;
for (auto &i : ranked_set) cout << i.ID_number_ << " " << i.virtue_grade_ << " " << i.talent_grade_ << endl;
return 0;
}