-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1028.cpp
More file actions
66 lines (62 loc) · 1.4 KB
/
1028.cpp
File metadata and controls
66 lines (62 loc) · 1.4 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct Mystruct
{
char name[20];//scanf输入字符串要求用char数组而不是string定义
int year;
int month;
int day;
}Peo;
bool cmp(Peo a, Peo b)//从年纪最大到年纪最小
{
if (a.year < b.year)
return true;
else if (a.year == b.year&&a.month < b.month)
return true;
else if (a.year == b.year&&a.month == b.month&&a.day < b.day)
return true;
else
return false;
}
int main()
{
vector<Peo> p;//vector存
int n, count=0;
cin >> n;
for (int i = 0; i < n; i++)
{
Peo temp;
char s[11];
scanf("%s %s",temp.name,s);//用scanf和printf,cin和cout会超时
temp.year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + s[3] - '0';
temp.month = (s[5] - '0') * 10 + s[6] - '0';
temp.day = (s[8] - '0') * 10 + s[9] - '0';//字符串转化成整数
if (temp.year > 1814 && temp.year < 2014)
{
p.push_back(temp);
count++;
}
else if((temp.year==1814&&temp.month>9)|| (temp.year == 1814 && temp.month==9&&temp.day>=6))
{
p.push_back(temp);
count++;
}
else if ((temp.year == 2014 && temp.month<9) || (temp.year == 2014 && temp.month == 9 && temp.day <= 6))
{
p.push_back(temp);
count++;
}
}
if (count > 0)
{
sort(p.begin(), p.end(), cmp);
printf("%d %s %s\n", count, p[0].name, p[count - 1].name);
}
else//考虑全是无效数据的情况
cout << "0" << endl;
return 0;
}