Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main(){
  9.     int q;
  10.     map<string, string> directory;
  11.     cin >> q;
  12.     for (int i = 0; i < q; ++i) {
  13.         string operation_code;
  14.         cin >> operation_code;
  15.         if (operation_code == "CHANGE_CAPITAL") {
  16.             string country, new_capital;
  17.             cin >> country >> new_capital;
  18.             if (directory.count(country) == 0) {
  19.                 directory[country] = new_capital;
  20.                 cout << "Introduce new country " << country << " with capital " << new_capital << endl;
  21.             }else {
  22.                 if (new_capital == directory[country]) {
  23.                     cout << "Country " << country << " hasn't changed its capital" << endl;
  24.                 }else {
  25.                     cout << "Country " << country << " has changed its capital from " << directory[country] << " to " << new_capital << endl;
  26.                     directory[country] = new_capital;
  27.                 }
  28.             }
  29.         }else {
  30.             if (operation_code == "RENAME") {
  31.                 string old_country_name, new_country_name;
  32.                 cin >> old_country_name >> new_country_name;
  33.                 if (old_country_name == new_country_name || directory.count(old_country_name) == 0 || directory.count(new_country_name) == 1) {
  34.                     cout << "Incorrect rename, skip" << endl;
  35.                 }else {
  36.                     cout << "Country " << old_country_name << " with capital " << directory[old_country_name] << "  has been renamed to " << new_country_name << endl;
  37.                     directory[new_country_name] = directory[old_country_name];
  38.                     directory.erase(old_country_name);
  39.                 }
  40.             }else {
  41.                 if (operation_code == "ABOUT") {
  42.                     string country;
  43.                     cin >> country;
  44.                     if (directory.count(country) == 0) {
  45.                         cout << "Country " << country << " doesn't exist" << endl;
  46.                     }else {
  47.                         cout << "Country " << country << " has capital " << directory[country] << endl;
  48.                     }
  49.                 }else {
  50.                     if (operation_code == "DUMP") {
  51.                         if (directory.size() == 0) {
  52.                             cout << "There are no countries in the world" << endl;
  53.                         }else {
  54.                             for (auto item : directory) {
  55.                                 cout << item.first << "/" << item.second << " ";
  56.                             }
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.  
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement