这道题目让我学会了sort函数()最后可以添加一个bool类型的cmp函数作为比较条件,其他就比较简单了
#include<iostream> #include<algorithm> using namespace std; struct member { string name; int year; int month; int day; int num; }oi[105]; int n; bool cmp(member a,member b) { if(a.year<b.year)return 1; if(a.year>b.year)return 0; if(a.year==b.year) { if(a.month<b.month)return 1; if(a.month>b.month)return 0; if(a.month==b.month) { if(a.day<b.day)return 1; if(a.day>b.day)return 0; if(a.day==b.day) { if(a.num>b.num)return 1; else return 0; } } } } int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>oi[i].name>>oi[i].year>>oi[i].month>>oi[i].day; oi[i].num=i; } sort(oi+1,oi+n+1,cmp); for(int i=1;i<=n;i++) { cout<<oi[i].name<<endl; } return 0; }
标签:p1104,return,oi,int,month,year,生日,day From: https://www.cnblogs.com/ataraxyyeah/p/17557475.html