1028 人口普查

水题。注意点,可能出现合理生日的总数为0的情况,要特判输出。

#include<iostream>
using namespace std;

int main() {
    int n,cnt = 0;
    string name,birthday;
    string youngest_name,youngest_birthday,oldest_name,oldest_birthday;
    cin>>n;
    while(n--) {
        cin>>name>>birthday;
        if( birthday >= "1814/09/06" && birthday <= "2014/09/06" ) {
            cnt++;
            if(youngest_birthday == "" || youngest_birthday < birthday) {//出生日期越大越年轻 
                youngest_birthday = birthday;
                youngest_name = name;
            }
            if(oldest_birthday == "" || oldest_birthday > birthday) {//出生日期越小越年长 
                oldest_birthday = birthday;
                oldest_name = name;
            }
        }
    }
    if(cnt == 0) cout<<cnt; //如果没有合理生日 
    else cout<<cnt<<" "<<oldest_name<<" "<<youngest_name;
    return 0;
}

 

 

posted @ 2020-02-18 12:02  tangq123  阅读(251)  评论(0编辑  收藏  举报