我是靠谱客的博主 疯狂人生,最近开发中收集的这篇文章主要介绍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;
}

最后

以上就是疯狂人生为你收集整理的PAT(Basic Level)_1028_人口普查的全部内容,希望文章能够帮你解决PAT(Basic Level)_1028_人口普查所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部