Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <set>
- #include <utility>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <iomanip>
- #include <cctype>
- std::string FindNameByYear(const std::map <int, std::string>& names, int year) {
- std::string ans;
- if (!names.empty()) {
- if (year >= names.begin() -> first) {
- auto it1 = names.upper_bound(year);
- ans = (--it1) -> second;
- }
- }
- return ans;
- }
- std::string HistoryOfNames(const std::map <int, std::string>& names, int year) {
- std::string ans;
- if (!names.empty()) {
- std::vector<std::string> buff;
- auto it_now = --names.upper_bound(year);
- int now_year = (--names.upper_bound(year))->first;
- std::string tmp;
- ans += " (";
- for (auto it = names.begin(); it != it_now; ++it) {
- if (it -> second != tmp) {
- ans += it -> second;
- ans += ", ";
- tmp = it -> second;
- }
- }
- ans += ") ";
- }
- return ans;
- }
- class Person {
- public:
- void ChangeFirstName(int year, const std::string& first_name) {
- first_names[year] = first_name;
- }
- void ChangeLastName(int year, const std::string& last_name) {
- last_names[year] = last_name;
- }
- std::string GetFullName(int year) {
- std::string first_name = FindNameByYear(first_names, year);
- std::string last_name = FindNameByYear(last_names, year);
- if (first_name.empty() && last_name.empty()) return "Incognito";
- else {
- if (first_name.empty()) return last_name + " with unknown first name";
- if (last_name.empty()) return first_name + " with unknown last name";
- return first_name + " " + last_name;
- }
- // получить имя и фамилию по состоянию на конец года year
- }
- std::string GetFullNameWithHistory(int year) {
- std::string first_name_now = FindNameByYear(first_names, year);
- std::string last_name_now = FindNameByYear(last_names, year);
- std::string first_name_history = HistoryOfNames (first_names, year);
- std::string last_name_history = HistoryOfNames (last_names, year);
- if (first_name_now.empty() && last_name_now.empty()) return "Incognito";
- else {
- if (first_name_now.empty()) return last_name_now + last_name_history + " with unknown first name";
- if (last_name_now.empty()) return first_name_now + first_name_history + " with unknown last name";
- return first_name_now + first_name_history + " " + last_name_now + last_name_history;
- }
- // получить все имена и фамилии по состоянию на конец года year
- }
- private:
- std::map <int, std::string> first_names;
- std::map <int, std::string> last_names;
- // приватные поля
- };
- int main() {
- Person person;
- person.ChangeFirstName(1900, "Eugene");
- person.ChangeLastName(1900, "Sokolov");
- person.ChangeLastName(1910, "Sokolov");
- person.ChangeFirstName(1920, "Evgeny");
- person.ChangeLastName(1930, "Sokolov");
- std::cout << person.GetFullNameWithHistory(1940) << std::endl;
- return 0;
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement