-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1028.cpp
61 lines (52 loc) · 1.32 KB
/
1028.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
52
53
54
55
56
57
58
59
60
61
#include<bits/stdc++.h>
using namespace std;
struct birth
{
string name;
int y;int m;int d;
int age;
}peo[1000];
bool compare(birth a,birth 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;
}
int main()
{
int n;
cin>>n;
string temp;
int cnt=0;
for(int i=0,j=0;j<n;i++,j++)
{
cin>>peo[i].name>>temp;
peo[i].y=stoi(temp.substr(0,4),nullptr,10);
peo[i].m=stoi(temp.substr(5,2),nullptr,10);
peo[i].d=stoi(temp.substr(8,2),nullptr,10);
peo[i].age=2014-peo[i].y;
if(peo[i].age==200)
{
if(peo[i].m-9<0) peo[i].age++;
else if(peo[i].m==9 && peo[i].d-6<0) peo[i].age++;
}
if(peo[i].age==0)
{
if(peo[i].m>9) peo[i].age--;
else if(peo[i].m==9&&peo[i].d>6) peo[i].age--;
}
if(peo[i].age<=200&&peo[i].age>=0)cnt++;
else --i;
}
sort(peo,peo+cnt,compare);//sort函数,需要输入 指针类型的数据
//存储较多的数据导致第四个测试点 无法通过
//测试点3:符合条件的人数为0时
if(cnt!=0)
cout<<cnt<<" "<<peo[0].name<<" "<<peo[cnt-1].name<<endl;
else cout<<"0"<<endl;
// for(int i=0;i<n;i++)
// cout<<peo[i].name;
}