#include<bits/stdc++.h>
using namespace std;
struct people{
char name[7];
int old;
}stu[5];
long long convert(int year,int month,int day){
return year*10000+month*100+day;
}
int main(){
int n,cnt=0;//1814,9,6----2014,9,6
int temp_year,temp_month,temp_day;
scanf("%d",&n);
bool flag=false;
for(int i=0;i<n;i++){
char temp_name[7];
scanf("%s %d/%d/%d",temp_name,&temp_year,&temp_month,&temp_day);
long long temp_sum=convert(temp_year,temp_month,temp_day);
if((temp_sum>=18140906)&&(temp_sum<=20140906)){
cnt++;
if(flag==false){
strcpy(stu[0].name,temp_name);
strcpy(stu[1].name,temp_name);
stu[0].old=temp_sum;
stu[1].old=temp_sum;
flag=true;
}
else{
if(temp_sum<stu[0].old){
strcpy(stu[0].name,temp_name);
stu[0].old=temp_sum;
}
if(temp_sum>stu[1].old){
strcpy(stu[1].name,temp_name);
stu[1].old=temp_sum;
}
}
}
}
if(cnt==0)printf("0\n");
else printf("%d %s %s\n",cnt,stu[0].name,stu[1].name);
return 0;
}
写给自己:我之前的错误一直在于,并不是多有i=0的时候才可以初始化最年长最年轻的人,因为有的时候i=0的时候并不满足这个范围(是不合理的数)。