Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<map>
- #include<string>
- #include<vector>
- using namespace std;
- class Person {
- private:
- map <int, string> surname;
- map<int, string> name;
- public:
- void ChangeFirstName(int year, const string& first_name) {
- name[year] = first_name;/*add first name at year*/
- }
- void ChangeLastName(int year, const string& last_name) {
- surname[year] = last_name;
- // добавить факт изменения фамилии на last_name в год year
- }
- string GetFullName(int year) {
- // получить имя и фамилию по состоянию на конец года
- string finded_name, finded_surname;
- int temp_year = 0U;
- for (auto n : name) {
- if (n.first > temp_year && n.first <= year) {
- finded_name = n.second;
- }
- }
- temp_year = 0U;
- for (auto s : surname) {
- if (s.first > temp_year && s.first <= year) {
- finded_surname = s.second;
- }
- }
- if (finded_name != "" && finded_surname != "") {
- return finded_name+" "+finded_surname;
- }
- else if (finded_name != "" && finded_surname == "") {
- return finded_name+ " with unknown last name";
- }
- else {
- return "Incognito";
- }
- }
- };
- int main(void) {
- Person person;
- person.ChangeFirstName(1965, "Polina");
- person.ChangeLastName(1967, "Sergeeva");
- for (int year : {1900, 1965, 1990}) {
- cout << person.GetFullName(year) << endl;
- }
- person.ChangeFirstName(1970, "Appolinaria");
- for (int year : {1969, 1970}) {
- cout << person.GetFullName(year) << endl;
- }
- person.ChangeLastName(1968, "Volkova");
- for (int year : {1969, 1970}) {
- cout << person.GetFullName(year) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement