提交时间:2023-04-09 15:51:33
运行 ID: 14205
#include<bits/stdc++.h> using namespace std; struct Patient{ string id; int age,num; }; bool cmp(Patient a,Patient b){ if(a.age>=60&&b.age<60){ return a.age>b.age; } else if(a.age>=60&&b.age>=60){ if(a.age!=b.age) return a.age>b.age; else return a.num<b.num; } else if(a.age<60&&b.age<60){ return a.num<b.num; } else if(a.age<60&&b.age>=60){ return a.age>b.age; } } int main(){ int n; cin>>n; Patient p[n]; for(int i=0;i<n;i++){ cin>>p[i].id>>p[i].age; p[i].num=i; } sort(p,p+n,cmp); for(int i=0;i<5;i++){ cout<<p[i].id<<endl; } return 0; }