pat 甲级 1062 Talent and Virtue

结构体排序
简单题

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int n,l,h,m;
struct stu{

    int num;
    int virtue;
    int talent;
    int total;
};

stu sage[11000], noble[11000], fool[11000], other[11000];
//vector<stu> sage, noble, fool, other;

bool cmp(stu a, stu b){
    if(a.total == b.total){
        if(a.virtue == b.virtue) return a.num < b.num;
        else return a.virtue > b.virtue;
    }
    else return a.total > b.total;
}

int main(){

    scanf("%d%d%d",&n,&l,&h);
    int q = 0, w = 0, e = 0, r = 0;
    int sum = 0;
    while(n != 0){
        int a;
        int c, d;
        scanf("%d%d%d",&a,&c,&d);
        if(c<l || d<l) {
            n--;
            continue;
        }
        else{
            sum++;
            if(c >= h && d >= h){
                sage[q].num = a;
                sage[q].virtue = c;
                sage[q].talent = d;
                sage[q].total = c + d;
                q++;
            }
            else if(d <= h && c  >= h){
                noble[w].num = a;
                noble[w].virtue = c;
                noble[w].talent = d;
                noble[w].total = c + d;
                w++;
            }
            else if(c <= h && d <= h && d <= c){
                fool[e].num = a;
                fool[e].virtue = c;
                fool[e].talent = d;
                fool[e].total = c + d;
                e++;
            }
            else {
                other[r].num = a;
                other[r].virtue = c;
                other[r].talent = d;
                other[r].total = c + d;
                r++;
            }           
            n--;
        }
    }
    printf("%d\n",sum);
    sort(sage,sage+q,cmp);
    for(int i=0; i<q; i++) printf("%d %d %d\n",sage[i].num,sage[i].virtue,sage[i].talent);
    sort(noble,noble+w,cmp);
    for(int i=0; i<w; i++) printf("%d %d %d\n",noble[i].num,noble[i].virtue,noble[i].talent);
    sort(fool,fool+e,cmp);
    for(int i=0; i<e; i++) printf("%d %d %d\n",fool[i].num,fool[i].virtue,fool[i].talent);
    sort(other,other+r,cmp);
    for(int i=0; i<r; i++) printf("%d %d %d\n",other[i].num,other[i].virtue,other[i].talent);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值