pat B 1028 人口普查

作死的选择算年龄,答非所问,不是好习惯,错了都不知哪里错了 - -、、、、、

#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;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值