洛谷——P1104 生日
阿新 • • 發佈:2017-12-03
ace reg cstring tro ios tchar 格式 復制 spa 復制
P1104 生日
題目描述
cjf君想調查學校OI組每個同學的生日,並按照從大到小的順序排序。但cjf君最近作業很多,沒有時間,所以請你幫她排序。
輸入輸出格式
輸入格式:
有2行,
第1行為OI組總人數n;
第2行至第n+1行分別是每人的姓名s、出生年y、月m、日d。
輸出格式:
有n行,
即n個生日從大到小同學的姓名。(如果有兩個同學生日相同,輸入靠後的同學先輸出)
輸入輸出樣例
輸入樣例#1: 復制3 Yangchu 1992 4 23 Qiujingya 1993 10 13 Luowen 1991 8 1輸出樣例#1:
Luowen Yangchu Qiujingya
說明
數據規模
1<n<100
length(s)<20
模擬
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define N 1010 using namespace std; int n; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar(); return x*f; } struct Node { string s; int y,m,d,num; }node[N]; int cmp(Node a,Node b) { if(a.y!=b.y) return a.y<b.y; if(a.m!=b.m) return a.m<b.m;if(a.d!=b.d) return a.d<b.d; return a.num>b.num; } int main() { n=read(); for(int i=1;i<=n;i++) { cin>>node[i].s; node[i].y=read(); node[i].m=read(); node[i].d=read(); node[i].num=i; } sort(node+1,node+1+n,cmp); for(int i=1;i<=n;i++) cout<<node[i].s<<endl; return 0; }
洛谷——P1104 生日