Advertisement
_takumi

Bus_stops_1

Aug 5th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     string s;
  8.     map<string, vector<string>> buses, stops;
  9.     for (int i = 0; i < n; i++) {
  10.         cin >> s;
  11.         if (s == "NEW_BUS") {
  12.             cin >> s;
  13.             int n;
  14.             cin >> n;
  15.             for (int j = 0; j < n; j++) {
  16.                 string stop;
  17.                 cin >> stop;
  18.                 buses[s].push_back(stop);
  19.                 stops[stop].push_back(s);
  20.             }
  21.         }
  22.         if (s == "ALL_BUSES") {
  23.             if (buses.empty())
  24.                 cout << "No buses" << endl;
  25.             else {
  26.                 for (auto j : buses) {
  27.                     cout << "Bus " << j.first << ":";
  28.                     for (int k = 0; k < j.second.size(); k++) {
  29.                         cout << " " << j.second[k];
  30.                     }
  31.                     cout << endl;
  32.                 }
  33.             }
  34.         }
  35.         if (s == "STOPS_FOR_BUS") {
  36.             cin >> s;
  37.             if (buses.find(s) == buses.end())
  38.                 cout << "No bus" << endl;
  39.             else {
  40.                 for (int j = 0; j < buses[s].size(); j++) {
  41.                     string stop = buses[s][j];
  42.                     cout << "Stop " << stop << ":";
  43.                     if (stops[stop].size() == 1)
  44.                         cout << " no interchange" << endl;
  45.                     else {
  46.                         for (int k = 0; k < stops[stop].size(); k++) {
  47.                             if (stops[stop][k] != s)
  48.                                 cout << " " << stops[stop][k];
  49.                         }
  50.                         cout << endl;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.         if (s == "BUSES_FOR_STOP") {
  56.             cin >> s;
  57.             if (stops.find(s) == stops.end())
  58.                 cout << "No stop";
  59.             else {
  60.                 for (int j = 0; j < stops[s].size(); j++) {
  61.                     cout << stops[s][j] << " ";
  62.                 }
  63.             }
  64.             cout << endl;
  65.         }
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement