1028


#include "stdafx.h"

#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<memory>
#include<fstream>
#include<map>
#include<utility>
#include<algorithm>

class Pat_Input
{
public:
    Pat_Input(std::ifstream &f, unsigned cor) { read_file(f, cor); };
    Pat_Input(std::istream &in, unsigned cor) { read_io(in, cor); }
    const std::vector<std::string> get_info()const { return info; }
private:
    std::vector<std::string> info;
    void read_file(std::ifstream &file, unsigned n);
    void read_io(std::istream &in, unsigned n);

};

void Pat_Input::read_file(std::ifstream &file, unsigned n)
{
    std::string tmp;
    for (unsigned i = 0; i < n; ++i)
    {
        try
        {
            std::getline(file, tmp);
            info.push_back(tmp);
        }
        catch (std::exception &err)
        {
            std::cout << err.what();
        }
    }
}
void Pat_Input::read_io(std::istream &in, unsigned n)
{
    std::string tmp;
    std::getline(in, tmp);
    for (unsigned i = 0; i < n; ++i)
    {
        try
        {
            std::getline(in, tmp);
            info.push_back(tmp);
        }
        catch (std::exception &err)
        {
            std::cout << err.what();
        }
    }
}




using namespace std;

class People_Age
{
public:
    People_Age() = default;

    void insert(const string &n, const string &b)
    {
        if (check(b))
            people.insert(pair<string, string>(n, b));
    }
    string get_max()
    {
        list_a();
        return list_age.back();
    }
    string get_min() { list_a(); return list_age.front(); }
    size_t get_count()const { return people.size(); }

private:
    bool check(const string &burn);
    vector<string> list_a();
    map<string, string> people;
    vector<string> list_age;
};

bool People_Age::check(const string &burn)
{
    string now = "2014/09/06";
    string old = "1814/09/06";
    if (burn<old || burn>now)
        return false;
    else
        return true;
}
vector<string> People_Age::list_a()
{
    vector<pair<string, string>> pv(people.begin(), people.end());
    sort(pv.begin(), pv.end(), [](const pair<string, string> &lhs, const pair<string, string> &rhs) {return lhs.second > rhs.second; });
    for (auto &r : pv)
    {
        list_age.push_back(r.first);
    }
    return list_age;
}

int main()
{
    ifstream file("C:\\Users\\winack\\Documents\\Visual Studio 2017\\Projects\\PAT\\test.txt");
    unsigned n;
    cin >> n;
    //Pat_Input tmp(file, n);
    Pat_Input tmp(cin, n);
    auto info = tmp.get_info();

    People_Age ps;

    string name;
    string burn;
    for (auto &r : info)
    {
        istringstream in(r);
        in >> name >> burn;
        ps.insert(name, burn);
    }

    cout << ps.get_count() << " " << ps.get_max() << " " << ps.get_min();

    return 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • [微风]【早安心语: 早安星期六,周杰伦的“告白气球”送给大家,希望能驱散连日来笼罩在大家心里的阴霾乌云。感谢@阿...
    曾艳芬微光站阅读 79评论 0 0
  • 我们每天都要思考很多不同的问题,很多问题之间又相互有冲突,这些冲突往往让我们的内心感到有压力。 虽然说有压力就有动...
    枫丹白露苏眉鱼阅读 280评论 4 2
  • 家人们,早上好! 星期六,不用着急去上班,晨起坐听鸟鸣啾啾,敲下几个字,开始美好的一天。 昨日秋游,没能给每个孩子...
    赵诚彬阅读 216评论 1 2
  • 1、易效能时间管理践行2.0/90天目标: 【学习】每天专业学习>2h 【亲子】断网高质量陪娃每天>1h 【践行目...
    微澜_12ca阅读 221评论 0 0
  • 今天是高秋霞老师的课程《勤勉入德》,高老师首先从现在的社会现状说起,现在社会已经进入学习型社会了,很多人家里都有书...
    真泥阅读 150评论 0 0