-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1028 人口普查.cpp
74 lines (69 loc) · 1.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
/*结果: 全部通过 */
#include<iostream>
#include<cstdio>
using namespace std;
struct person{
char name[6];
int yy,mm,dd;
};
bool pd(int y,int mm,int dd){
if(y==2014){
if(mm==9){
if(dd<=6) return true;
else return false;
}
else if(mm<9)
return true;
else
return false;
}
if(y==1814){
if(mm==9){
if(dd>=6) return true;
else return false;
}
else if(mm>9)
return true;
else
return false;
}
if(y<1814 || y>2014) return false;
return true;
}
bool compare(person a1,person a2){ //a1>a2 返回true a1<a2 返回false
if(a1.yy>a2.yy) return 0;
if(a1.yy<a2.yy) return 1;
//年份相当
if(a1.mm>a2.mm) return 0;
if(a1.mm<a2.mm) return 1;
//月份相当
if(a1.dd>a2.dd) return 0;
if(a1.dd<a2.dd) return 1;
return false;
}
int main(){
int n;cin>>n;
int right=0;
person old,yonth;
old.yy=2015;
yonth.yy=1813;
for(int i=0;i<n;i++){
person temp;
scanf("%s %d/%d/%d",&temp.name,&temp.yy,&temp.mm,&temp.dd);
//cout<<temp.name<<temp.yy<<temp.mm<<temp.dd;
if(pd(temp.yy,temp.mm,temp.dd)){
if(compare(temp,old)) //如果temp比old年长
old=temp;
if(!compare(temp,yonth)) //如果temp比yonth年轻
yonth=temp;
right++;
}
}
if(!right){
cout<<0;
}
else{
cout<<right<<' '<<old.name<<' '<<yonth.name;
}
return 0;
}