解题思路:
sort排序
注意事项:
参考代码:
#include<iostream> #include<algorithm> #include<stdio.h> using namespace std; const int N = 1e5+10; struct edge{ //结构体 int m,d,y; }; int cmp(edge a,edge b) //排序 { if(a.y==b.y) //如果年是相等的话则比较其他的 { if(a.m==b.m) { a.d<b.d; } return a.m<b.m; } return a.y<b.y; } int main() { edge edges[200]; int n=0; while(scanf("%d/%d/%d",&edges[n].m,&edges[n].d,&edges[n].y)!=EOF) n++; sort(edges,edges+n,cmp); for(int i=0;i<n;i++) printf("%02d/%02d/%02d\n",edges[i].m,edges[i].d,edges[i].y); return 0; }
0.0分
3 人评分