pat_b_1028 人口普查

     

              http://pat.zju.edu.cn/contests/pat-b-practise/1028


             分析: 没有符合条件的输出0

 

             代码:

                       

<span style="font-size:18px;">//人口普查
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=100004;

struct node
{
    char name[10];
    int y,m,d;
}a[maxn];

int cmp(node x,node z)
{
    if(x.y==z.y){
       if(x.m==z.m){
          return x.d<z.d;
       }
       return x.m<z.m;
    }
    return x.y<z.y;
}

bool isOld(node e)
{
    if(e.y<1814) return true;
    if(e.y>1814) return false;

    if(e.m>9) return false;
    if(e.m<9) return true;

    if(e.d>=6) return false;
    else       return true;
}

bool isNew(node e)
{
    if(e.y>2014) return true;
    if(e.y<2014) return false;

    if(e.m>9) return true;
    if(e.m<9) return false;

    if(e.d>6) return true;
    else      return false;
}


int main()
{
    freopen("in.txt","r",stdin);

    int n,m;
    char _max[10],_min[10];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %d/%d/%d",a[i].name,&a[i].y,&a[i].m,&a[i].d);
    }
    sort(a,a+n,cmp);
    m=n;
    for(int i=0;i<n;i++){
        if(isOld(a[i])) {m--; continue;}
        else{
            strcpy(_max,a[i].name);
            break;
        }
    }

    for(int i=n-1;i>=0;i--){
        if(isNew(a[i])) {m--; continue;}
        else{
            strcpy(_min,a[i].name);
            break;
        }
    }
    if(m!=0)
       printf("%d %s %s\n",m,_max,_min);
    else puts("0");
    return 0;
}
</span>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值