Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10.     int Q, stop_count;
  11.     cin >> Q;
  12.     string command, bus, stop;
  13.  
  14.     map<string, vector<string>> buses, stops;
  15.  
  16.     for (int i = 0; i < Q; ++i) {
  17.  
  18.         cin >> command;
  19.  
  20.         if (command == "NEW_BUS"){
  21.  
  22.             cin >> bus >> stop_count;
  23.  
  24.             for (int j = 0; j < stop_count; ++j) {
  25.                 cin >> stop;
  26.                 buses[bus].push_back(stop);
  27.                 stops[stop].push_back(bus);
  28.             }
  29.  
  30.             continue;
  31.         };
  32.  
  33.         if (command == "BUSES_FOR_STOP"){
  34.  
  35.             cin >> stop;
  36.  
  37.             if (stops.count(stop) == 0){
  38.                 cout << "No stop" << endl;
  39.             } else {
  40.                 for (auto x : stops[stop]){
  41.                     cout << x << ' ';
  42.                 }
  43.                 cout << endl;
  44.             }
  45.  
  46.         };
  47.  
  48.         if (command == "STOPS_FOR_BUS"){
  49.  
  50.             cin >> bus;
  51.  
  52.             if (buses.count(bus) == 0){
  53.                 cout << "No bus" << endl;
  54.             } else{
  55.                 for (auto x : buses[bus]){
  56.                     cout << "Stop " << x << ": ";
  57.                     if (stops[x].size() != 1) {
  58.                         for (auto y : stops[x]) {
  59.                             if (y == bus) continue;
  60.                             cout << y << " ";
  61.                         }
  62.                         cout << endl;
  63.                     } else{
  64.                         cout << "no interchange" << endl;
  65.                     }
  66.  
  67.                 }
  68.             }
  69.  
  70.         };
  71.  
  72.         if (command == "ALL_BUSES"){
  73.  
  74.             if (!buses.empty()){
  75.                 for (auto x : buses){
  76.                     cout << "Bus " << x.first << ": ";
  77.                     for (auto y : x.second){
  78.                         cout << y << " ";
  79.                     }
  80.                     cout << endl;
  81.                 }
  82.             } else{
  83.                 cout << "No buses" << endl;
  84.             }
  85.  
  86.         };
  87.  
  88.  
  89.     }
  90.  
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement