Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <cassert>
- #include <vector>
- #include <map>
- using namespace std;
- enum class QueryType {
- NewBus,
- BusesForStop,
- StopsForBus,
- AllBuses
- };
- struct Query {
- QueryType type;
- string bus;
- string stop;
- vector<string> stops;
- };
- istream& operator >> (istream& is, Query& q) {
- // Реализуйте эту функцию
- string command;
- is >> command;
- if (command == "NewBus"){
- q.type = QueryType::NewBus;
- is >> q.bus;
- int stop_count;
- is >> stop_count;
- q.stops.resize(stop_count);
- for (string& stop:q.stops){
- is >> stop;
- }
- } else if (command == "BusesForStop"){
- q.type = QueryType::BusesForStop;
- is >> q.stop;
- } else if (command == "StopsForBus"){
- q.type = QueryType::StopsForBus;
- is >> q.bus;
- } else if (command == "AllBuses"){
- q.type = QueryType::AllBuses;
- }
- return is;
- }
- struct BusesForStopResponse {
- // Наполните полями эту структуру
- vector <string> buses;
- };
- ostream& operator << (ostream& os, const BusesForStopResponse& r) {
- // Реализуйте эту функцию
- if (r.buses.empty()){
- os << "No stop" << endl;
- } else {
- for(const string& bus:r.buses){
- os << bus << " ";
- }
- os << endl;
- }
- return os;
- }
- struct StopsForBusResponse {
- // Наполните полями эту структуру
- vector <string> stops;
- map<string, vector<string>> stb;
- };
- ostream& operator << (ostream& os, const StopsForBusResponse& r) {
- // Реализуйте эту функцию
- if (r.stops.empty()){
- os << "No bus" << endl;
- } else{
- for(const string& stop:r.stops){
- os << "Stop" << stop << ": ";
- if(r.stb.at(stop).size() == 1){
- os << "no interchange";
- } else {
- for (const string& other_bus:r.stb.at(stop)){
- if(r.bus != other_bus){
- os << other_bus << " ";
- }
- }
- }
- os << endl;
- }
- }
- return os;
- }
- struct AllBusesResponse {
- // Наполните полями эту структуру
- map<string, vector<string>> bts;
- };
- ostream& operator << (ostream& os, const AllBusesResponse& r) {
- // Реализуйте эту функцию
- if(r.bts.empty()){
- os << "No buses" << endl;
- } else {
- for (const auto& bus_item : r.bts){
- os << "Bus" << bus_item.first << ": ";
- for (const string& stop:bus_item.second){
- os << stop << " ";
- }
- os << endl;
- }
- }
- return os;
- }
- class BusManager {
- public:
- void AddBus(const string& bus, const vector<string>& stops) {
- // Реализуйте этот метод
- }
- BusesForStopResponse GetBusesForStop(const string& stop) const {
- // Реализуйте этот метод
- }
- StopsForBusResponse GetStopsForBus(const string& bus) const {
- // Реализуйте этот метод
- }
- AllBusesResponse GetAllBuses() const {
- // Реализуйте этот метод
- }
- private:
- };
- // Не меняя тела функции main, реализуйте функции и классы выше
- int main() {
- int query_count;
- Query q;
- cin >> query_count;
- BusManager bm;
- for (int i = 0; i < query_count; ++i) {
- cin >> q;
- switch (q.type) {
- case QueryType::NewBus:
- bm.AddBus(q.bus, q.stops);
- break;
- case QueryType::BusesForStop:
- cout << bm.GetBusesForStop(q.stop) << endl;
- break;
- case QueryType::StopsForBus:
- cout << bm.GetStopsForBus(q.bus) << endl;
- break;
- case QueryType::AllBuses:
- cout << bm.GetAllBuses() << endl;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement