# 【PAT乙级】1028 人口普查(20)

5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20


3 Tom John

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct people{
int year, month, day;
string name;
};
bool cmp(people p1, people p2)
{
if (p1.year != p2.year)
return p1.year < p2.year;
else if (p1.month != p2.month)
return p1.month < p2.month;
else
return p1.day < p2.day;
}
int main()
{
int n,tmpye,tmpmon,tmpday;
string na;
people tmpperson;
vector <people> person;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> na;
scanf("%d/%d/%d", &tmpye, &tmpmon, &tmpday);
tmpperson.name = na;
tmpperson.year = tmpye;
tmpperson.month = tmpmon;
tmpperson.day = tmpday;
if (tmpye < 1814 || (tmpye == 1814 && tmpmon < 9) || (tmpye == 1814 && tmpmon == 9 && tmpday < 6) || tmpye > 2014 || (tmpye == 2014 && tmpmon > 9) || (tmpye == 2014 && tmpmon == 9 && tmpday > 6))
continue;
else
person.push_back(tmpperson);
}
sort(person.begin(), person.end(), cmp);
cout<<person.size();
if(person.size()!=0)
cout<< " "<<person.front().name <<" "<<person.back().name;
return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main()
{
int maxyear = 9999, maxmonth = 9999, maxday = 9999;
int minyear = 0, minmonth = 0, minday = 0;
int n,tmpye,tmpmon,tmpday,count=0;
string na,minname,maxname;
cin >> n;
for (int i = 0; i < n; i++){
cin >> na;
scanf("%d/%d/%d", &tmpye, &tmpmon, &tmpday);
if (tmpye < 1814 || (tmpye == 1814 && tmpmon < 9) || (tmpye == 1814 && tmpmon == 9 && tmpday < 6) || tmpye > 2014 || (tmpye == 2014 && tmpmon > 9) || (tmpye == 2014 && tmpmon == 9 && tmpday > 6))
continue;
else{
count++;
if (tmpye > minyear || (tmpye == minyear&&tmpmon > minmonth) || (tmpye == minyear&&tmpmon == minmonth&&tmpday > minday))
{
minyear = tmpye; minmonth = tmpmon; minday = tmpday; minname = na;
}
if (tmpye < maxyear || (tmpye == maxyear&&tmpmon < maxmonth) || (tmpye == maxyear&&tmpmon == maxmonth&&tmpday < maxday))
{
maxyear = tmpye; maxmonth = tmpmon; maxday = tmpday; maxname = na;
}
}
}
cout << count;
if (count!=0)
cout<<" " << maxname <<" "<< minname;
return 0;
}