有一点需要注意,如果有效生日数量是0,则输出0
代码实现:
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
char name[10]; int year, month, day;
}birth;
int Judge(birth item)
{
if (item.year < 1814)return 0;
else if (item.year == 1814 && item.month < 9)return 0;
else if (item.year == 1814 && item.month == 9 && item.day < 6)return 0;
else if (item.year > 2014)return 0;
else if (item.year == 2014 && item.month > 9)return 0;
else if (item.year == 2014 && item.month == 9 && item.day > 6)return 0;
else return 1;
}
int main()
{
int N;
scanf("%d", &N);
birth *a = (birth*)malloc(sizeof(birth)*N);
int cnt = 0;
for (int i = 0; i < N; i++)
{
birth item;
scanf("%s %d/%d/%d", item.name, &item.year, &item.month, &item.day);
if (Judge(item) == 1)a[cnt] = item, cnt++;
}
int oindex = 0, yindex = 0;
for (int i = 0; i < cnt; i++)
if (a[oindex].year > a[i].year)oindex = i;
else if (a[oindex].year == a[i].year&&a[oindex].month > a[i].month)oindex = i;
else if (a[oindex].year == a[i].year&&a[oindex].month == a[i].month&&a[oindex].day > a[i].day)oindex = i;
for (int i = 0; i < cnt; i++)
if (a[yindex].year < a[i].year)yindex = i;
else if (a[yindex].year == a[i].year&&a[yindex].month < a[i].month)yindex = i;
else if (a[yindex].year == a[i].year&&a[yindex].month == a[i].month&&a[yindex].day < a[i].day)yindex = i;
if (cnt != 0)printf("%d %s %s", cnt, a[oindex].name, a[yindex].name);
else printf("0");
return 0;
}