Advertisement
Guest User

asd

a guest
Jan 22nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main(void)
  10. {
  11.     int q = 0;
  12.     string command;
  13.     string bus_stop;
  14.     int stop_counts = 0;
  15.     string bus;
  16.     map<string, vector<string>> buses;
  17.  
  18.  
  19.     cin >> q;
  20.     for(int i=0; i < q; i++)
  21.     {
  22.         cin >> command;
  23.  
  24.         if(command == "NEW_BUS")
  25.         {
  26.             cin >> bus >> stop_counts;
  27.             for(int b=0; b < stop_counts; b++ )
  28.             {
  29.                 cin >> bus_stop;
  30.                 buses[bus].push_back(bus_stop);
  31.             }
  32.         }
  33.         else if(command == "BUSES_FOR_STOP")
  34.         {
  35.             cin >> bus_stop;
  36.             int cnt = 0;
  37.             for (const auto& cnt_bus : buses)//(int cnt_bus = 0; cnt_bus < buses.size(); cnt_bus++)
  38.             {
  39.               for (const string& cnt_stop : cnt_bus.second)//(int cnt_stop = 0; cnt_stop < bus_stops[cnt_bus]; cnt_stop++)
  40.               {
  41.                   if(bus_stop == cnt_stop)
  42.                   {
  43.                       cnt++;
  44.                       cout << cnt_bus.first << " ";
  45.                   }
  46.               }
  47.             }
  48.             if(cnt==0)
  49.             {
  50.                 cout << "No stop" << endl;
  51.             }
  52.             else
  53.             {
  54.                 cout << endl;
  55.             }
  56.         }
  57.         else if(command == "STOPS_FOR_BUS")
  58.         {
  59.             cin >> bus;
  60.             if(buses.count(bus) > 0)
  61.             {
  62.                 for(const string& bus_stop : buses[bus])
  63.                 {
  64.                    cout << "Stop " << bus_stop << ": ";
  65.                    int cnt = 0;
  66.                    for (const auto& cnt_bus : buses)//(int cnt_bus = 0; cnt_bus < buses.size(); cnt_bus++)
  67.                    {
  68.                        if(cnt_bus.first != bus)
  69.                        {
  70.                            for (const string& cnt_stop : cnt_bus.second)//(int cnt_stop = 0; cnt_stop < bus_stops[cnt_bus]; cnt_stop++)
  71.                            {
  72.                                if(bus_stop == cnt_stop)
  73.                                {
  74.                                    cnt++;
  75.                                    cout << cnt_bus.first << " ";
  76.                                }
  77.                            }
  78.                        }
  79.                    }
  80.                    if(cnt==0)
  81.                    {
  82.                        cout << "no interchange" << endl;
  83.                    }
  84.                    else
  85.                    {
  86.                        cout << endl;
  87.                    }
  88.                 }
  89.             }
  90.             else
  91.             {
  92.                 cout << "No bus" << endl;
  93.             }
  94.  
  95.         }
  96.         else if (command == "ALL_BUSES")
  97.         {
  98.             if(false==buses.empty())
  99.             {
  100.                 for(const auto& cnt_bus :buses)
  101.                 {
  102.                     cout << "Bus " << cnt_bus.first << ": ";
  103.                     for (const string& cnt_stop : cnt_bus.second)
  104.                     {
  105.                         cout << cnt_stop << " ";
  106.                     }
  107.                     cout << endl;
  108.                 }
  109.             }
  110.             else
  111.             {
  112.                 cout << "No buses" << endl;
  113.             }
  114.         }
  115.     }
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement