// ConsoleApplication14.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<algorithm>
#include<math.h>
using namespace std;
struct birthday {
char name[10];
int year;
int month;
int day;
int birth;
};
birthday per[110000], ok[110000];
bool cmp(birthday x, birthday y) {
if (x.birth < y.birth)
return true;
else
return false;
}
int main()
{
int n;
char a[100];
int r = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> per[i].name >> a;
per[i].year = (a[0] - '0') * 1000 + (a[1] - '0') * 100 + (a[2] - '0') * 10 + (a[3] - '0');
per[i].month = (a[5] - '0') * 10 + (a[6] - '0');
per[i].day = (a[8] - '0') * 10 + (a[9] - '0');
per[i].birth = (a[0] - '0')*pow(10, 7) + (a[1] - '0')*pow(10, 6) + (a[2] - '0') *pow(10, 5) + (a[3] - '0')*pow(10, 4) + (a[5] - '0') *pow(10, 3) + (a[6] - '0') * 100 + (a[8] - '0') * 10 + (a[9] - '0');
if (per[i].birth >= 18140906 && per[i].birth <= 20140906) {
ok[r] = per[i];
r++;
}
}
sort(ok, ok + r, cmp);
if(r>0)//针对测试点3(有可能输入的日期全都不合理,这时运行else,输出0即可)
cout << r << " " << ok[0].name << " " << ok[r - 1].name;
else
cout<<0;
}
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门使用技巧:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
PAT 1028人口普查 测试点3是坑,小心啊
猜你喜欢
转载自blog.csdn.net/w17390956947/article/details/104517251
今日推荐
周排行