-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1028_人口普查 (20).cpp
51 lines (44 loc) · 1.16 KB
/
1028_人口普查 (20).cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cctype>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <set>
using namespace std;
class Person {
public:
char name[20];
int y, m ,d;
bool operator<(const Person & other) const {
if (this->y == other.y) {
if (this->m == other.m) return this->d < other.d;
else return this->m < other.m;
} else return this->y < other.y;
};
};
vector<Person> personList;
/*
*/
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
Person personIns;
scanf("%s %d/%d/%d", personIns.name, &personIns.y, &personIns.m, &personIns.d);
// pay attention to invalid age
int age = 2014 - personIns.y;
if (age > 200 || (age == 200 && (personIns.m < 9 || (personIns.m == 9 && personIns.d < 6)))) continue;
if (age < 0 || (age == 0 && (personIns.m > 9 || (personIns.m == 9 && personIns.d > 6)))) continue;
personList.push_back(personIns);
}
sort(personList.begin(), personList.end());
if (personList.size() == 0)
printf("0\n");
else
printf("%d %s %s\n", personList.size(), personList[0].name, personList[personList.size()-1].name);
return 0;
}