zoukankan      html  css  js  c++  java
  • B1028. 人口普查

     

     基本思路

    • 定义一个结构体person,persion的属性是姓名和生日
    • 生日用年、月、日来表示
    • 合法性判断(左右边界判断),先检查年,再检查月,最后检查日
    #include <bits/stdc++.h>
    
    using namespace std;
    
    struct Person {
        char name[10];
        int yy, mm, dd;
    }youngest, oldest, left_p, right_p, temp;
    
    void init() {
        youngest.yy = left_p.yy = 1814;
        youngest.mm = left_p.mm = 9;
        youngest.dd = left_p.dd = 6;
        oldest.yy = right_p.yy = 2014;
        oldest.mm = right_p.mm = 9;
        oldest.dd = right_p.dd = 6;
    }
    
    bool younger(Person person, Person target) {
        if (person.yy != target.yy) {
            return person.yy < target.yy;
        }
        if (person.mm != person.mm) {
            return person.mm < target.mm;
        }
        if (person.dd != person.dd) {
            return person.dd < target.dd;
        }    
        return false;
    }
    
    bool older(Person person, Person target) {
        if (person.yy != target.yy) { 
            return person.yy > target.yy;
        }
        if (person.mm != person.mm) {
            return person.mm > target.mm;
        }
        if (person.dd != person.dd) {
            return person.dd > target.dd;
        }
        return false;
    }
    
    int main(int argc, char* argv[]) {
        init();
        int N, yy, mm, dd, num = 0;
        cin >> N;    
        for (int i = 0; i < N; i++) {
            scanf("%s %d/%d/%d", temp.name, &temp.yy, &temp.mm, &temp.dd);
            if (younger(temp, right_p) && older(temp, left_p)) {
                num++;        
                if (younger(youngest, temp)) {
                    youngest = temp;
                }
            
                if (older(oldest, temp)) {
                    oldest = temp;
                }
            }
        }
        cout << num << ' ' << oldest.name << ' ' << youngest.name << ' ' << endl;
        return 0;
    }
  • 相关阅读:
    POJ 1860 Currency Exchange (Bellman ford)
    POJ 1502 MPI Maelstrom (最短路)
    2015 Multi-University Training Contest 2 1006(DFS)
    HDU 1495 非常可乐(枚举+DFS)
    HDU 5289 Assignment(单调队列)
    ACDream 1734 Can you make a water problem?(贪心)
    ACDream 1735 输油管道
    ACDream 1726 A Math game (折半查找)
    CSU 1602 Needle Throwing Game (投针问题)
    CSU 1604 SunnyPig (BFS)
  • 原文地址:https://www.cnblogs.com/YC-L/p/12271755.html
Copyright © 2011-2022 走看看