2423: 【普及-】【P1104】生日

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:8 解决:5

题目描述

cjf 君想调查学校 OI 组每个同学的生日,并按照年龄从大到小的顺序排序。但 cjf 君最近作业很多,没有时间,所以请你帮她排序。

输入

输入共有 lns="http://www.w3.org/1998/Math/MathML">+1 行,

第 lns="http://www.w3.org/1998/Math/MathML">1 行为 OI 组总人数 lns="http://www.w3.org/1998/Math/MathML">

第 lns="http://www.w3.org/1998/Math/MathML">2 行至第 lns="http://www.w3.org/1998/Math/MathML">+1 行分别是每人的姓名 lns="http://www.w3.org/1998/Math/MathML">、出生年 lns="http://www.w3.org/1998/Math/MathML">、月 lns="http://www.w3.org/1998/Math/MathML">、日 lns="http://www.w3.org/1998/Math/MathML">

输出

输出共有 lns="http://www.w3.org/1998/Math/MathML"> 行,

即 lns="http://www.w3.org/1998/Math/MathML"> 个生日从大到小同学的姓名。(如果有两个同学生日相同,输入靠后的同学先输出)

样例输入 复制

3
Yangchu 1992 4 23
Qiujingya 1993 10 13
Luowen 1991 8 1

样例输出 复制

Luowen
Yangchu
Qiujingya

提示

数据保证,lns="http://www.w3.org/1998/Math/MathML">1<<100lns="http://www.w3.org/1998/Math/MathML">1<20。保证年月日实际存在,且年份 lns="http://www.w3.org/1998/Math/MathML">[1960,2020]

#include<bits/stdc++.h>
using namespace std;
struct node {
	string s;
	int y;
	int m;
	int d;
	int i;
};
node a[110];
int n;
bool cmp(node p1,node p2) {
	if (p1.y!=p2.y) return p1.y<p2.y;
	if (p1.m!=p2.m) return p1.m<p2.m;
	if (p1.d!=p2.d) return p1.d<p2.d;
	return p1.i>p2.i;
}
int main(){
    cin>>n;
    for (int i=1;i<=n;i++) {
    	cin>>a[i].s>>a[i].y>>a[i].m>>a[i].d;
    	a[i].i=i;
	}
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++) {
		cout<<a[i].s<<endl;
	}
	return 0;
}