zoukankan      html  css  js  c++  java
  • PAT|1028 人口普查(简单模拟)

    注意点:1.最年长人的出生日期是1814/9/6 

                   2.最年轻人的出生日期是2014/9/6 

                   3.存在输入样例均不在合理日期内 应只输出0

    思路:将符合条件的加入进结构体数组中,并对他们进行排序,输出最大最小即可。

    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <cstring>
    #include <vector>
    using namespace std;
    const int maxn = 0x3f3f3f3f;
    typedef long long ll;
    struct Node{
        string a;
        int b,c,d;
    }w[100005];
    bool cmp(Node p,Node q) {
        if(p.b != q.b) return p.b < q.b;
        if(p.c != q.c) return p.c < q.c;
        if(p.d != q.d)  return p.d < q.d;
        return p.a < q.a;
    }
    int main() {
        int n;
        cin >> n;
        string a;
        int b,c,d;
        int t = 0;
        for(int i = 1; i <= n; i++) {
            cin >> a;
            scanf("%d/%d/%d",&b,&c,&d);
    
            if((b == 2014 && c == 9 && d >6) || (b == 1814 && c == 9 && d < 6) || (b == 2014 && c > 9 ) ||(b > 2014) ||(b == 1814 && c < 9)||(b < 1814)) {
                    continue;
            }
            else {
                w[t].a = a;
                w[t].b = b;
                w[t].c = c;
                w[t++].d = d;
            }
            //
        }
        sort(w,w+t,cmp);
        cout << t;
        if(t != 0)
        cout << " " << w[0].a << " " << w[t-1].a<<endl;
        return 0;
    }
  • 相关阅读:
    Python try/except/finally
    EmailMessage类
    HTML DOM 初学笔记
    JavaScript 初学备忘录
    html style标签
    Django 导出csv文件 中文乱码问题
    Html 列表实现展开和收起
    Django CreateView 简单使用
    Django用户认证
    Nginx负载均衡配置实例详解
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/12200373.html
Copyright © 2011-2022 走看看