• PAT甲题题解-1062. Talent and Virtue (25)-排序水题


    水题,分组排序即可。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <string.h>
    
    using namespace std;
    /*
    太水水水。。。
    */
    const int maxn=100000+5;
    int cnt1,cnt2,cnt3,cnt4;
    struct Node{
        int id;
        int tot;
        int vir;
        int tal;
        bool operator<(const Node tmp)const{
            if(tot==tmp.tot){
                if(vir==tmp.vir)
                    return id<tmp.id;
                else
                    return vir>tmp.vir;
            }
            else
                return tot>tmp.tot;
    
        }
    }sages[maxn],noble[maxn],fool[maxn],small[maxn];
    
    int main()
    {
        int n,L,H;
        int a,b,c;
        scanf("%d %d %d",&n,&L,&H);
        for(int i=1;i<=n;i++){
            scanf("%d %d %d",&a,&b,&c);
            if(b<L || c<L)
                continue;
            if(b>=H && c>=H){
                sages[cnt1].id=a;
                sages[cnt1].vir=b;
                sages[cnt1].tal=c;
                sages[cnt1].tot=b+c;
                cnt1++;
            }
            else if(b>=H && c<H && c>=L){
                noble[cnt2].id=a;
                noble[cnt2].vir=b;
                noble[cnt2].tal=c;
                noble[cnt2].tot=b+c;
                cnt2++;
            }
            else if(b<H && c<H &&b>=c){
                fool[cnt3].id=a;
                fool[cnt3].vir=b;
                fool[cnt3].tal=c;
                fool[cnt3].tot=b+c;
                cnt3++;
            }
            else{
                small[cnt4].id=a;
                small[cnt4].vir=b;
                small[cnt4].tal=c;
                small[cnt4].tot=b+c;
                cnt4++;
            }
        }
        sort(sages,sages+cnt1);
        sort(noble,noble+cnt2);
        sort(fool,fool+cnt3);
        sort(small,small+cnt4);
        printf("%d
    ",cnt1+cnt2+cnt3+cnt4);
        for(int i=0;i<cnt1;i++){
            printf("%08d %d %d
    ",sages[i].id,sages[i].vir,sages[i].tal);
        }
        for(int i=0;i<cnt2;i++){
            printf("%08d %d %d
    ",noble[i].id,noble[i].vir,noble[i].tal);
        }
        for(int i=0;i<cnt3;i++){
            printf("%08d %d %d
    ",fool[i].id,fool[i].vir,fool[i].tal);
        }
        for(int i=0;i<cnt4;i++){
            printf("%08d %d %d
    ",small[i].id,small[i].vir,small[i].tal);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    HDOJ 4747 Mex
    HDU 1203 I NEED A OFFER!
    HDU 2616 Kill the monster
    HDU 3496 Watch The Movie
    Codeforces 347A A. Difference Row
    Codeforces 347B B. Fixed Points
    Codeforces 372B B. Hungry Sequence
    HDU 1476 Sudoku Killer
    HDU 1987 How many ways
    HDU 2564 词组缩写
  • 原文地址:https://www.cnblogs.com/chenxiwenruo/p/6497015.html
Copyright © 2020-2023  润新知