1.0输入的所有数据均合法但不合理的情况, 输出0;
2.结构体没有指针可以直接复制
3.用string和cin,cout来输入输出最后一个测试点会超时
4.用一个for循环边输入边判断条件是否符合
我的代码(最后一个测试点过不了):
#include<iostream>
#include<string>
using namespace std;
struct citizen {string name;int year;int month;int day;
}old, young;
int main() {int N;int count = 0;string _name; int year, month, day;old.year = 9999; old.month = 9999; old.day = 9999;young.year = 0; young.month = 0; young.day = 0;cin >> N;for (int j = 0; j<N; j++) {cin >> _name;scanf("%d/%d/%d", &year, &month, &day);if (((year >1814) || (year == 1814 && month>9) || (year == 1814 && month == 9 && day >= 6)) &&((year<2014) || (year == 2014 && month<9) || (year == 2014 && month == 9 && day <= 6))) {count++;if (year > young.year || (year == young.year&&month > young.month)|| (year == year&&month == young.month&&day > young.day)) {young.name = _name; young.year = year; young.month = month; young.day = day;}if (year < old.year || (year == old.year&&month < old.month)|| (year == old.year&&month == old.month&&day < old.day)) {old.name = _name; old.year = year; old.month = month; old.day = day;}}}printf("%d", count);if (count != 0) {printf(" %s %s", old.name.c_str(), young.name.c_str());}return 0;}