Advertisement
Spocoman

03. Cities by Continent and Country

Jan 21st, 2024
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.  
  12.     map<string, map<string, set<string>>> info;
  13.  
  14.     string continent, country, city;
  15.  
  16.     for (size_t i = 0; i < n; i++) {
  17.         cin >> continent >> country >> city;
  18.         info[continent][country].insert(city);
  19.     }
  20.  
  21.     for (auto i = info.begin(); i != info.end(); i++) {
  22.         cout << '\n' << i->first << ':';
  23.  
  24.         for (auto j = i->second.begin(); j != i->second.end(); j++) {
  25.             cout << '\n' << j->first << " -> ";
  26.             int len = j->second.size();
  27.             for (auto k = j->second.begin(); k != j->second.end(); k++) {
  28.                 cout << k->c_str();
  29.                 if (--len != 0) {
  30.                     cout << ", ";
  31.                 }
  32.             }
  33.         }
  34.     }
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement