Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <vector>
- #include <algorithm>
- using namespace std;
- //функция, проверяющая, есть ли в векторе определенная строка
- bool FindVector (const vector <string>& a, const string& b) {
- for (const auto& m : a) {
- if (m == b) {
- return true;
- }
- }
- return false;
- }
- int main () {
- map <string, vector<string>> bus_to_stops;
- map <string, vector<string>> stop_to_buses;
- int Q;
- cin >> Q;
- for (int i = 0; i < Q; ++i) {
- string code;
- cin >> code;
- if (code == "NEW_BUS") {
- string bus;
- int stop_count;
- cin >> bus >> stop_count;
- for (int w = 0; w < stop_count; ++w) {
- string stop;
- cin >> stop;
- bus_to_stops[bus].push_back(stop);
- stop_to_buses[stop].push_back(bus);
- }
- }
- else if (code == "BUSES_FOR_STOP") {
- string stop;
- int th = 0;
- cin >> stop;
- for (const auto& x : bus_to_stops) {
- if (FindVector(x.second, stop) == 1) {
- cout << x.first << " ";
- th++;
- }
- }
- if (th == 0) {
- cout << "No stop";
- }
- cout << endl;
- }
- else if (code == "STOPS_FOR_BUS") {
- string bus;
- cin >> bus;
- if (bus_to_stops[bus].empty() == 1) {
- cout << "No bus" << endl;
- bus_to_stops.erase(bus);
- }
- else {
- for (const auto &t : bus_to_stops[bus]) {
- cout << "Stop " << t << ": ";
- if (stop_to_buses[t].size() == 1)
- cout << "no interchange" << endl;
- else {
- for (const auto &u : stop_to_buses[t]) {
- if (u != bus)
- cout << u << " ";
- }
- cout << endl;
- }
- }
- }
- }
- else if (code == "ALL_BUSES") {
- if (bus_to_stops.empty() == 1)
- cout << "No buses" << endl;
- else {
- for (const auto& x : bus_to_stops) {
- cout << "Bus " << x.first << ": ";
- for (const auto& r : x.second) {
- cout << r << " ";
- }
- cout << endl;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement