作死的选择算年龄,答非所问,不是好习惯,错了都不知哪里错了 - -、、、、、
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;
struct birth{
char *ch;
int age;
};
int cmp(struct birth a,struct birth b){
return a.age < b.age;
}
/*
int cmp(const void *aa,const void *bb){
struct birth* a = (struct birth* ) aa;
struct birth* b = (struct birth* ) bb;
return a->age > b->age;
}
*/
int main(){
int N;
scanf("%d",&N);
struct birth births[N];
int cou = 0;
for(int i = 0;i < N;i ++){
int tempage = 0;
char *ch1 = new char[6];
char *ch2 = new char[11];
scanf("%s %s",ch1,ch2);
int month = 0;
int day = 0;
tempage = (ch2[0] - '0')*1000+(ch2[1] - '0')*100+(ch2[2] - '0')*10+(ch2[3] - '0');
//printf("%d\n",tempage);
if(tempage > 2014){
continue;
}
if(tempage < 1814){
continue;
}
tempage = 2014 - tempage;
month = (ch2[5] - '0') * 10 + (ch2[6] - '0');
day = (ch2[8] - '0') * 10 + (ch2[9] - '0');
//printf("%d %d\n",month,day);
if(tempage == 200&&month < 9){
continue;
}
if(tempage == 200&&month == 9&&day < 6){
continue;
}
if(month > 9&&tempage == 0){
continue;
}
if(month == 9&&tempage == 0&&day > 6){
continue;
}
if(month > 9){
tempage ++;
}
if(month == 9){
if(day > 6){
tempage ++;
}
}
births[cou].ch = ch1;
births[cou].age = tempage;
cou++;
}
//qsort(births,cou,sizeof(birth),cmp);
sort(births,births+cou,cmp);
if(cou == 0)//若为0,输出为此格式。
printf("0\n");
else
printf("%d %s %s\n",cou,births[cou - 1].ch,births[0].ch);
return 0;
}