#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;
}
网友评论