Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <algorithm>
- #include <cctype>
- #include <functional>
- #include <iostream>
- #include <map>
- #include <vector>
- #include <set>
- #include <string>
- #include <numeric>
- using namespace std;
- class Person
- {
- public:
- using events = map<int, string>;
- void ChangeFirstName(int year, const string &first_name)
- {
- first_names[year] = first_name;
- }
- void ChangeLastName(int year, const string &last_name)
- {
- second_names[year] = last_name;
- }
- string GetFullName(int year)
- {
- events::const_iterator fn, sn;
- bool fn_status = FindName(first_names, year, fn);
- bool sn_status = FindName(second_names, year, sn);
- if (fn_status && sn_status)
- return fn->second + " " + sn->second;
- else if (fn_status && !sn_status)
- return fn->second + " with unknown last name";
- else if (!fn_status && sn_status)
- return sn->second + " with unknown first name";
- else
- return "Incognito";
- }
- string GetFullNameWithHistory(int year)
- {
- events::const_iterator fn, sn;
- bool fn_status = FindName(first_names, year, fn);
- bool sn_status = FindName(second_names, year, sn);
- if (fn_status && sn_status)
- {
- return fn->second + " " + sn->second;
- }
- else if (fn_status && !sn_status)
- {
- string res = fn->second + " (";
- for (auto it = make_reverse_iterator(fn); it != second_names.rend(); ++it)
- res += it->second + ", ";
- res[res.size() - 2] = ')';
- return fn->second + "with unknown last name";
- }
- else if (!fn_status && sn_status)
- {
- return sn->second + " with unknown first name";
- }
- else
- {
- return "Incognito";
- }
- }
- private:
- events first_names, second_names;
- bool FindName(const events& event_list, const int& year, events::const_iterator& out)
- {
- bool flag = false;
- if ( event_list.size() == 0)
- return flag;
- int last_change = event_list.begin()->first;
- for (auto event = event_list.begin(); event != event_list.end(); ++event)
- {
- if (event->first <= year && event->first >= last_change)
- {
- out = event;
- last_change = event->first;
- flag = true;
- }
- }
- return flag;
- }
- };
- int main() {
- Person person;
- person.ChangeFirstName(1965, "Polina");
- person.ChangeLastName(1967, "Sergeeva");
- for (int year : {1900, 1965, 1990}) {
- cout << person.GetFullNameWithHistory(year) << endl;
- }
- person.ChangeFirstName(1970, "Appolinaria");
- for (int year : {1969, 1970}) {
- cout << person.GetFullNameWithHistory(year) << endl;
- }
- person.ChangeLastName(1968, "Volkova");
- for (int year : {1969, 1970}) {
- cout << person.GetFullNameWithHistory(year) << endl;
- }
- person.ChangeFirstName(1990, "Polina");
- person.ChangeLastName(1990, "Volkova-Sergeeva");
- cout << person.GetFullNameWithHistory(1990) << endl;
- person.ChangeFirstName(1966, "Pauline");
- cout << person.GetFullNameWithHistory(1966) << endl;
- person.ChangeLastName(1960, "Sergeeva");
- for (int year : {1960, 1967}) {
- cout << person.GetFullNameWithHistory(year) << endl;
- }
- person.ChangeLastName(1961, "Ivanova");
- cout << person.GetFullNameWithHistory(1967) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement