cmp的多关键字排序
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6;
struct node{
string s;
int num,year,mon,day;
}a[maxn];
bool cmp(node a,node b)
{
if(a.year!=b.year)
return a.year<b.year;
else
{
if(a.mon!=b.mon)
{
return a.mon<b.mon;
}
else if(a.mon==b.mon&&a.day!=b.day)
return a.day<b.day;
else if(a.mon==b.mon&&a.day==b.day)
return a.num>b.num;
}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].s>>a[i].year>>a[i].mon>>a[i].day;
a[i].num=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
cout<<a[i].s<<endl;
return 0;
}
sort函数好香