Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <map>
- #include <set>
- using namespace std;
- typedef long long ll;
- class Person {
- public:
- void ChangeFirstName(int year, const string& first_name) {
- // добавить факт изменения имени на first_name в год year
- f_name[year] = first_name;
- }
- void ChangeLastName(int year, const string& last_name) {
- // добавить факт изменения фамилии на last_name в год year
- s_name[year] = last_name;
- }
- string GetName(const map<int, string> &dict, int year) {
- string res;
- vector<string> ss;
- vector<string> s;
- for (auto it = dict.rbegin(); it != dict.rend(); ++it)
- if (it->first <= year)
- ss.push_back(it->second);
- if (!ss.empty()) {
- s.push_back(ss[0]);
- res += s[0];
- }
- for (int i = 1; i < ss.size(); ++i)
- if (ss[i] != ss[i - 1])
- s.push_back(ss[i]);
- if (s.size() > 1) {
- res += " (";
- for (int i = 1; i < s.size(); ++i)
- if (!i || s[i] != s[i - 1]) {
- res += s[i];
- if (s.size() > 2 && i < s.size() - 1)
- res += ", ";
- }
- res += ")";
- }
- return res;
- }
- string GetFullName(int year) {
- // получить имя и фамилию по состоянию на конец года year
- string res;
- for (auto it = f_name.rbegin(); it != f_name.rend(); ++it)
- if (it->first <= year) {res += it->second; break;}
- res += " ";
- for (auto it = s_name.rbegin(); it != s_name.rend(); ++it)
- if (it->first <= year) {res += it->second; break;}
- if (res == " ")
- res = "Incognito";
- else if (res[0] == ' ') {
- res.erase(0, 1);
- res += " with unknown first name";
- }
- else if (res[res.size() - 1] == ' ')
- res += "with unknown last name";
- return res;
- }
- string GetFullNameWithHistory(int year) {
- string res;
- res += GetName(f_name, year);
- res += " ";
- res += GetName(s_name, year);
- if (res == " ")
- res = "Incognito";
- else if (res[0] == ' ') {
- res.erase(0, 1);
- res += " with unknown first name";
- }
- else if (res[res.size() - 1] == ' ')
- res += "with unknown last name";
- return res;
- }
- private:
- // приватные поля
- map<int, string> f_name;
- map<int, string> s_name;
- };
- /*int main() {
- Person person;
- person.ChangeFirstName(1900, "Eugene");
- person.ChangeLastName(1900, "Sokolov");
- person.ChangeLastName(1910, "Sokolov");
- person.ChangeFirstName(1920, "Evgeny");
- person.ChangeLastName(1930, "Sokolov");
- cout << person.GetFullNameWithHistory(1940) << endl;
- return 0;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement