SHARE
TWEET

country_list

infplusf Jan 24th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. using std :: string;
  6. using std :: map;
  7. using std :: cin;
  8. using std :: cout;
  9. using std :: endl;
  10.  
  11. void print_map(const map<string, string>& n) {
  12. for (const auto& it : n)
  13.     cout << it.first << "/" << it.second << " ";
  14. }
  15.  
  16. int main() {
  17.     int n;
  18.     cin >> n;
  19.     map<string, string> list;
  20.     for (int i = 0; i < n; i++) {
  21.         string operation;
  22.         cin >> operation;
  23.         if (operation == "CHANGE_CAPITAL") {
  24.             string country, new_capital;
  25.             cin >> country >> new_capital;
  26.             if (list.count(country) == 0)
  27.                 cout << "Introduce new country " << country << " with capital " << new_capital << endl;
  28.             else {
  29.                 const string& old_capital = list[country];
  30.                 if (old_capital == new_capital)
  31.                     cout << "Country " << country << " hasn't changed its capital" << endl;
  32.                 else
  33.                     cout << "Country " << country << " has changed its capital from " << old_capital << " to " << new_capital << endl;
  34.             }
  35.             list[country] = new_capital;
  36.         }
  37.         else if (operation == "RENAME") {
  38.             string new_country, old_country;
  39.             cin >> old_country >> new_country;
  40.             if (old_country == new_country || list.count(old_country) == 0 || list.count(new_country) == 1)
  41.                 cout << "Incorrect rename, skip" << endl;
  42.             else {
  43.                 cout << "Country " << old_country << " with capital " << list[old_country] << " has been renamed to "
  44.                      << new_country << endl;
  45.                 list[new_country] = list[old_country];
  46.                 list.erase(old_country);
  47.             }
  48.         }
  49.         else if (operation == "ABOUT") {
  50.             string country;
  51.             cin >> country;
  52.             if (list.count(country) == 0)
  53.                 cout << "Country " << country << " doesn't exist " << endl;
  54.             else
  55.                 cout << "Country " << country << " has capital " << list[country] << endl;
  56.         }
  57.         else if (operation == "DUMP") {
  58.            if (list.empty())
  59.                cout << "There are no countries in the world" << endl;
  60.            else
  61.                print_map(list);
  62.         }
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top