PAT (Basic Level) Practice 德才论

题目链接:德才论

受教,司马缸。

a:德分
b:才分

四类人:

  1. 德才全尽,a >= H,b >= H
  2. 德胜才,a >= H,L <= b <H
  3. 德才兼亡尚有德胜才,L <= a < H,L <= b < H,a >= b
  4. 德才兼亡,a >= L,b >= L
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
    int a,b,c;
};
Node stu1[100010];
Node stu2[100010];
Node stu3[100010];
Node stu4[100010];
int len1,len2,len3,len4;
bool cmp(Node x,Node y)
{
    if(x.a+x.b>y.a+y.b) return true;
    if(x.a+x.b==y.a+y.b&&x.a>y.a) return true;
    if(x.a+x.b==y.a+y.b&&x.a==y.a&&x.c<y.c) return true;
    return false;
}
int main()
{
    int n,l,h,aa,bb,cc;
    scanf("%d%d%d",&n,&l,&h);
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&cc,&aa,&bb);
        if(aa>=h&&bb>=h){
            stu1[len1].a=aa;
            stu1[len1].b=bb;
            stu1[len1++].c=cc;
        }
        else if(aa>=h&&bb>=l&&bb<h){
            stu2[len2].a=aa;
            stu2[len2].b=bb;
            stu2[len2++].c=cc;
        }
        else if(aa<h&&bb<h&&aa>=bb&&bb>=l&&aa>=l){
            stu3[len3].a=aa;
            stu3[len3].b=bb;
            stu3[len3++].c=cc;
        }
        else if(aa>=l&&bb>=l){
            stu4[len4].a=aa;
            stu4[len4].b=bb;
            stu4[len4++].c=cc;
        }
    }
    sort(stu1,stu1+len1,cmp);
    sort(stu2,stu2+len2,cmp);
    sort(stu3,stu3+len3,cmp);
    sort(stu4,stu4+len4,cmp);
    printf("%d\n",len1+len2+len3+len4);
    for(int i=0;i<len1;i++){
        printf("%d %d %d\n",stu1[i].c,stu1[i].a,stu1[i].b);
    }
    for(int i=0;i<len2;i++){
        printf("%d %d %d\n",stu2[i].c,stu2[i].a,stu2[i].b);
    }
    for(int i=0;i<len3;i++){
        printf("%d %d %d\n",stu3[i].c,stu3[i].a,stu3[i].b);
    }
    for(int i=0;i<len4;i++){
        printf("%d %d %d",stu4[i].c,stu4[i].a,stu4[i].b);
        if(i<len4-1) printf("\n");
    }
    return 0;
}

发布了10 篇原创文章 · 获赞 0 · 访问量 106

猜你喜欢

转载自blog.csdn.net/m0_46383408/article/details/104446920