1055. The World's Richest (25)

时间:2022-12-31 04:17:45

题目链接:1055. The World's Richest (25)

结构体排序

#include<bits/stdc++.h>
const int maxn =100100;
using namespace std;

int n,k,m,st,en;
struct Node{
    string name;
    int age;
    int net;
    bool operator < (const Node &a)const  {
        if(a.net!=net)return net>a.net;
        else {
            if(a.age!=age)return age<a.age;
            else return name<a.name;
        }
    }
}a[maxn];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++){
        cin>>a[i].name;
        scanf("%d%d",&a[i].age,&a[i].net);
    }
    sort(a,a+n);

int cnt=0,temp;
    while(k--){
        scanf("%d%d%d",&m,&st,&en);
        temp=m;
        printf("Case #%d:\n",++cnt);
        for(int i=0;i<n;i++){
            if(a[i].age>=st&&a[i].age<=en){
                cout<<a[i].name;
                printf(" %d %d\n",a[i].age,a[i].net);
                m--;
            }
            if(m==0)break;
        }
        if(temp-m==0)
        cout<<"None"<<endl;
    }
    return 0;
}