P1104. 生日

考点

  • 排序

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>

using namespace std;

const int LEN = 250;

struct Student
{
string s_;
int idx_, y_, m_, d_;
} stu[LEN];

bool cmp(Student a, Student b)
{
if (a.y_ != b.y_)
return a.y_ < b.y_;
else if (a.m_ != b.m_)
return a.m_ < b.m_;
else if (a.d_ != b.d_)
return a.d_ < b.d_;
return a.idx_ > b.idx_;
}

int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> stu[i].s_ >> stu[i].y_ >> stu[i].m_ >> stu[i].d_;
stu[i].idx_ = i;
}
sort(stu, stu + n, cmp);
for (int i = 0; i < n; ++i)
cout << stu[i].s_ << endl;
return 0;
}

思路

没有坑点,按照要求编写sort函数即可