Advertisement
cska1312

Untitled

May 11th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <utility>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. vector<string> continentsOrder, countriesOrder;
  11. map<string, map<string, string>> places;
  12. int n;
  13. cin >> n;
  14. while (n != 0) {
  15. //continent country city
  16. string data, continent, country, city, val = "";
  17. getline(cin >> ws, data);
  18. for (int k = 0; k <= data.length(); k++) {
  19. if (data[k] == ' ' || k == data.length()) {
  20. if (continent == "") {
  21. continent = val;
  22. }
  23. else if (country == "") {
  24. country = val;
  25. }
  26. else {
  27. city = val;
  28. }
  29. val = "";
  30. }
  31. else {
  32. val += data[k];
  33. }
  34. }
  35. auto find = places.find(continent);
  36. if (find == places.end()) {
  37. continentsOrder.push_back(continent);
  38. map<string, string> locations;
  39. places[continent] = locations;
  40.  
  41. }
  42. map<string, string>& mapLink = places[continent];
  43. auto find2 = mapLink.find(country);
  44. if (find2 == mapLink.end()) {
  45. countriesOrder.push_back(country);
  46. mapLink[country] = "";
  47. }
  48. if (mapLink[country].length() > 0) {
  49. mapLink[country] += ", ";
  50. }
  51. mapLink[country] += city;
  52. n--;
  53. }
  54.  
  55. for (string c : continentsOrder) {
  56. auto continent = places.find(c);
  57. cout << continent->first << ":\n";
  58.  
  59. for (string c2 : countriesOrder) {
  60. auto country = places[continent->first].find(c2);
  61. if (country != places[continent->first].end()) {
  62. cout << " " << country->first << " -> " << country->second << endl;
  63. }
  64. else {
  65. continue;
  66. }
  67. }
  68.  
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement