Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- map<string, vector<string >> route;
- vector <string> buses; // Примитивный и тупой костыль для обхода необходимости сортировки
- bool On_route(const vector<string> &arr, string s) {
- for (auto t: arr) {
- if (t == s) {
- return true;
- }
- }
- return false;
- }
- int main() {
- int Q;
- cin >> Q;
- for (auto i = 0; i < Q; ++i) {
- string choice{};
- cin >> choice;
- if (choice == "NEW_BUS") {
- int count;
- string bus_n, stop_name;
- vector<string> stops;
- cin >> bus_n >> count;
- if (route.count(bus_n) == 0) {
- for (auto i = 0; i < count; ++i) {
- cin >> stop_name;
- stops.push_back(stop_name);
- }
- route[bus_n] = stops;
- buses.push_back(bus_n); // И копию в вектор для запоминания порядка добавления.
- }
- } else if (choice == "BUSES_FOR_STOP") {
- string s_name;
- bool flag {false};
- cin >> s_name;
- if (route.size() != 0) {
- for (const auto &t : buses) {
- if (On_route(route.find ( t ) -> second, s_name)) {
- flag = true;
- cout << t << " ";
- }
- if ( !flag ){
- cout << "No stop " << endl;}
- }
- cout << endl;
- } else {
- cout << "No stop " << endl;
- }
- } else if (choice == "STOPS_FOR_BUS") {
- string bus_n;
- cin >> bus_n;
- bool flag{false};
- if (route.count(bus_n)) {
- for (const auto &t: route.find(bus_n)->second) {
- flag = false;
- cout << "Stop " << t << ": ";
- for (const auto &bus : buses) {
- if ((route.find (bus)->first != bus_n) and (On_route(route.find(bus)->second, t))) {
- cout << bus << " ";
- flag = true;
- }
- }
- if (!flag) {
- cout << "no interchange";
- }
- cout << endl;
- }
- } else {
- cout << "No bus" << endl;
- }
- } else if (choice == "ALL_BUSES") {
- if (route.size() != 0) {
- for (const auto &t : route) {
- cout << "Bus " << t.first << ": ";
- for (const auto &j : t.second) {
- cout << j << " ";
- }
- cout << endl;
- }
- } else {
- cout << "No buses" << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement