#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;
}
1028
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1、易效能时间管理践行2.0/90天目标: 【学习】每天专业学习>2h 【亲子】断网高质量陪娃每天>1h 【践行目...