Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- using namespace std;
- int main() {
- int Q, stop_count;
- cin >> Q;
- string command, bus, stop;
- map<string, vector<string>> buses, stops;
- for (int i = 0; i < Q; ++i) {
- cin >> command;
- if (command == "NEW_BUS"){
- cin >> bus >> stop_count;
- for (int j = 0; j < stop_count; ++j) {
- cin >> stop;
- buses[bus].push_back(stop);
- stops[stop].push_back(bus);
- }
- continue;
- };
- if (command == "BUSES_FOR_STOP"){
- cin >> stop;
- if (stops.count(stop) == 0){
- cout << "No stop" << endl;
- } else {
- for (auto x : stops[stop]){
- cout << x << ' ';
- }
- cout << endl;
- }
- };
- if (command == "STOPS_FOR_BUS"){
- cin >> bus;
- if (buses.count(bus) == 0){
- cout << "No bus" << endl;
- } else{
- for (auto x : buses[bus]){
- cout << "Stop " << x << ": ";
- if (stops[x].size() != 1) {
- for (auto y : stops[x]) {
- if (y == bus) continue;
- cout << y << " ";
- }
- cout << endl;
- } else{
- cout << "no interchange" << endl;
- }
- }
- }
- };
- if (command == "ALL_BUSES"){
- if (!buses.empty()){
- for (auto x : buses){
- cout << "Bus " << x.first << ": ";
- for (auto y : x.second){
- cout << y << " ";
- }
- cout << endl;
- }
- } else{
- cout << "No buses" << endl;
- }
- };
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement