PAT 甲级 1062 Talent and Virtue

PAT 甲级 1062 Talent and Virtue

#include<bits/stdc++.h>
using namespace std;
//type_ == 0 is small man; type_ == 1 is fool man;
//type_ == 2 is noblemen; type_ == 3 is sages;
//type_ == -1 is defualt;
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);//freopen("output.txt", "w", stdout);
#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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值