Advertisement
dmitrytrc

Untitled

May 20th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. map<string, vector<string >> route;
  10. vector <string> buses; // Примитивный и тупой костыль для обхода необходимости сортировки
  11.  
  12. bool On_route(const vector<string> &arr, string s) {
  13.     for (auto t: arr) {
  14.         if (t == s) {
  15.             return true;
  16.         }
  17.     }
  18.     return false;
  19. }
  20.  
  21. int main() {
  22.  
  23.     int Q;
  24.     cin >> Q;
  25.  
  26.     for (auto i = 0; i < Q; ++i) {
  27.         string choice{};
  28.         cin >> choice;
  29.         if (choice == "NEW_BUS") {
  30.             int count;
  31.             string bus_n, stop_name;
  32.             vector<string> stops;
  33.             cin >> bus_n >> count;
  34.             if (route.count(bus_n) == 0) {
  35.                 for (auto i = 0; i < count; ++i) {
  36.                     cin >> stop_name;
  37.                     stops.push_back(stop_name);
  38.                 }
  39.                 route[bus_n] = stops;
  40.                 buses.push_back(bus_n); // И копию в вектор для запоминания порядка добавления.
  41.             }
  42.         } else if (choice == "BUSES_FOR_STOP") {
  43.             string s_name;
  44.             bool flag {false};
  45.             cin >> s_name;
  46.  
  47.             if (route.size() != 0) {
  48.                 for (const auto &t : buses) {
  49.                     if (On_route(route.find ( t ) -> second, s_name)) {
  50.                         flag = true;
  51.                         cout << t << " ";
  52.                     }
  53.  
  54.                 if ( !flag ){
  55.                     cout << "No stop " << endl;}
  56.                 }
  57.                 cout << endl;
  58.             } else {
  59.                 cout << "No stop " << endl;
  60.             }
  61.  
  62.         } else if (choice == "STOPS_FOR_BUS") {
  63.             string bus_n;
  64.             cin >> bus_n;
  65.             bool flag{false};
  66.  
  67.             if (route.count(bus_n)) {
  68.  
  69.                 for (const auto &t: route.find(bus_n)->second) {
  70.  
  71.                     flag = false;
  72.                     cout << "Stop " << t << ": ";
  73.                     for (const auto &bus : buses) {
  74.                         if ((route.find (bus)->first != bus_n) and (On_route(route.find(bus)->second, t))) {
  75.                             cout << bus << " ";
  76.                             flag = true;
  77.                         }
  78.                     }
  79.                     if (!flag) {
  80.                         cout << "no interchange";
  81.                     }
  82.                     cout << endl;
  83.                 }
  84.  
  85.             } else {
  86.                 cout << "No bus" << endl;
  87.             }
  88.  
  89.         } else if (choice == "ALL_BUSES") {
  90.  
  91.  
  92.             if (route.size() != 0) {
  93.  
  94.  
  95.              for (const auto &t : route) {
  96.                     cout << "Bus " << t.first << ": ";
  97.                     for (const auto &j : t.second) {
  98.                         cout << j << " ";
  99.                     }
  100.                     cout << endl;
  101.                 }
  102.             } else {
  103.                 cout << "No buses" << endl;
  104.             }
  105.  
  106.         }
  107.     }
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement