PAT(Basic Level)_1028_人口普查

#include<stdio.h>
#include<string.h>

struct Tip{
    char name[10];
    int year;
    int month;
    int day;
};

int cmp(const Tip &A,const Tip &B){
    if(A.year!=B.year) return A.year-B.year;
    if(A.month!=B.month) return A.month-B.month;
    return A.day-B.day;
}

int main(){
    int N;
    scanf("%d",&N);

    Tip max={"",2014,9,6};
    Tip min={"",1814,9,6};
    Tip tmp;

    Tip oldest={"",2014,9,6};
    Tip youngest={"",1814,9,6};

    int cnt=0;
    while(N--){
        scanf("%s %d/%d/%d",tmp.name,&tmp.year,&tmp.month,&tmp.day);
        if(cmp(tmp,max)>0) continue;
        if(cmp(tmp,min)<0) continue;
        cnt++;
        if(cmp(tmp,youngest)>0){
            strcpy(youngest.name,tmp.name);
            youngest.year=tmp.year;
            youngest.month=tmp.month;
            youngest.day=tmp.day;
        }
        if(cmp(tmp,oldest)<0){
            strcpy(oldest.name,tmp.name);
            oldest.year=tmp.year;
            oldest.month=tmp.month;
            oldest.day=tmp.day;
        }
    }

    if(cnt==0) putchar('0');//测试点3 
    else printf("%d %s %s",cnt,oldest.name,youngest.name);

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值