题解 | 最小年龄的3个职工
#include <bits/stdc++.h>
#include <vector>
using namespace std;
struct Cop{
int id;
string name;
int age;
Cop(int id,string name,int age):id(id),name(name),age(age){}
bool operator <(Cop b){
if(age==b.age){
if(id==b.id){
return name<b.name;
}else return id<b.id;
}else return age<b.age;
}
};
int main(){
int n;
while(cin>>n){
vector<Cop>a;
while(n--){
int id,age;string name;
cin>>id>>name>>age;
a.push_back(Cop(id,name,age));
}
sort(a.begin(),a.end());
for(int i=0;i<3;i++){
cout<<a[i].id<<" "<<a[i].name<<" "<<a[i].age<<endl;
}
}
}
自定义排序

查看8道真题和解析