Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <vector>
- using namespace std;
- int main(void)
- {
- int q = 0;
- string command;
- string bus_stop;
- int stop_counts = 0;
- string bus;
- map<string, vector<string>> buses;
- cin >> q;
- for(int i=0; i < q; i++)
- {
- cin >> command;
- if(command == "NEW_BUS")
- {
- cin >> bus >> stop_counts;
- for(int b=0; b < stop_counts; b++ )
- {
- cin >> bus_stop;
- buses[bus].push_back(bus_stop);
- }
- }
- else if(command == "BUSES_FOR_STOP")
- {
- cin >> bus_stop;
- int cnt = 0;
- for (const auto& cnt_bus : buses)//(int cnt_bus = 0; cnt_bus < buses.size(); cnt_bus++)
- {
- for (const string& cnt_stop : cnt_bus.second)//(int cnt_stop = 0; cnt_stop < bus_stops[cnt_bus]; cnt_stop++)
- {
- if(bus_stop == cnt_stop)
- {
- cnt++;
- cout << cnt_bus.first << " ";
- }
- }
- }
- if(cnt==0)
- {
- cout << "No stop" << endl;
- }
- else
- {
- cout << endl;
- }
- }
- else if(command == "STOPS_FOR_BUS")
- {
- cin >> bus;
- if(buses.count(bus) > 0)
- {
- for(const string& bus_stop : buses[bus])
- {
- cout << "Stop " << bus_stop << ": ";
- int cnt = 0;
- for (const auto& cnt_bus : buses)//(int cnt_bus = 0; cnt_bus < buses.size(); cnt_bus++)
- {
- if(cnt_bus.first != bus)
- {
- for (const string& cnt_stop : cnt_bus.second)//(int cnt_stop = 0; cnt_stop < bus_stops[cnt_bus]; cnt_stop++)
- {
- if(bus_stop == cnt_stop)
- {
- cnt++;
- cout << cnt_bus.first << " ";
- }
- }
- }
- }
- if(cnt==0)
- {
- cout << "no interchange" << endl;
- }
- else
- {
- cout << endl;
- }
- }
- }
- else
- {
- cout << "No bus" << endl;
- }
- }
- else if (command == "ALL_BUSES")
- {
- if(false==buses.empty())
- {
- for(const auto& cnt_bus :buses)
- {
- cout << "Bus " << cnt_bus.first << ": ";
- for (const string& cnt_stop : cnt_bus.second)
- {
- cout << cnt_stop << " ";
- }
- cout << endl;
- }
- }
- else
- {
- cout << "No buses" << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement