Advertisement
QuiteDiamond

Untitled

Jan 25th, 2022
853
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <set>
  4. #include <utility>
  5. #include <vector>
  6. #include <map>
  7. #include <algorithm>
  8. #include <iomanip>
  9. #include <cctype>
  10.  
  11. std::string FindNameByYear(const std::map <int, std::string>& names, int year) {
  12.     std::string ans;
  13.     if (!names.empty()) {
  14.         if (year >= names.begin() -> first) {
  15.             auto it1 = names.upper_bound(year);
  16.             ans =  (--it1) -> second;
  17.         }
  18.     }
  19.     return ans;
  20. }
  21.  
  22. std::string HistoryOfNames(const std::map <int, std::string>& names, int year) {
  23.     std::string ans;
  24.     if (!names.empty()) {
  25.         std::vector<std::string> buff;
  26.         auto it_now = --names.upper_bound(year);
  27.         int now_year = (--names.upper_bound(year))->first;
  28.         std::string tmp;
  29.         ans += " (";
  30.         for (auto it = names.begin(); it != it_now; ++it) {
  31.             if (it -> second != tmp) {
  32.                 ans += it -> second;
  33.                 ans += ", ";
  34.                 tmp = it -> second;
  35.             }
  36.         }
  37.         ans += ") ";
  38.     }
  39.     return ans;
  40. }
  41.  
  42. class Person {
  43. public:
  44.     void ChangeFirstName(int year, const std::string& first_name) {
  45.         first_names[year] = first_name;
  46.     }
  47.     void ChangeLastName(int year, const std::string& last_name) {
  48.         last_names[year] = last_name;
  49.     }
  50.     std::string GetFullName(int year) {
  51.         std::string first_name = FindNameByYear(first_names, year);
  52.         std::string last_name = FindNameByYear(last_names, year);
  53.  
  54.         if (first_name.empty() && last_name.empty()) return "Incognito";
  55.         else {
  56.             if (first_name.empty()) return last_name + " with unknown first name";
  57.             if (last_name.empty()) return first_name + " with unknown last name";
  58.             return first_name + " " + last_name;
  59.         }
  60.  
  61.         // получить имя и фамилию по состоянию на конец года year
  62.     }
  63.     std::string GetFullNameWithHistory(int year) {
  64.         std::string first_name_now = FindNameByYear(first_names, year);
  65.         std::string last_name_now = FindNameByYear(last_names, year);
  66.         std::string first_name_history = HistoryOfNames (first_names, year);
  67.         std::string last_name_history = HistoryOfNames (last_names, year);
  68.  
  69.         if (first_name_now.empty() && last_name_now.empty()) return "Incognito";
  70.         else {
  71.             if (first_name_now.empty()) return last_name_now + last_name_history + " with unknown first name";
  72.             if (last_name_now.empty()) return first_name_now + first_name_history + " with unknown last name";
  73.             return first_name_now + first_name_history + " " + last_name_now + last_name_history;
  74.         }
  75.  
  76.         // получить все имена и фамилии по состоянию на конец года year
  77.     }
  78.  
  79. private:
  80.     std::map <int, std::string> first_names;
  81.     std::map <int, std::string> last_names;
  82.     // приватные поля
  83. };
  84.  
  85.  
  86. int main() {
  87.     Person person;
  88.  
  89.     person.ChangeFirstName(1900, "Eugene");
  90.     person.ChangeLastName(1900, "Sokolov");
  91.     person.ChangeLastName(1910, "Sokolov");
  92.     person.ChangeFirstName(1920, "Evgeny");
  93.     person.ChangeLastName(1930, "Sokolov");
  94.     std::cout << person.GetFullNameWithHistory(1940) << std::endl;
  95.  
  96.     return 0;
  97. }
  98.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement