// BusSystem.h #ifndef BUSSYSTEM_H #define BUSSYSTEM_H #include <vector> #include <string> #include <map> struct Time { int hours; int minutes; Time(int h = 0, int m = 0) : hours(h), minutes(m) {} bool operator<(const Time& other) const { return hours < other.hours || (hours == other.hours && minutes < other.minutes); } bool operator<=(const Time& other) const { return *this < other || *this == other; } bool operator==(const Time& other) const { return hours == other.hours && minutes == other.minutes; } Time operator+(int addMinutes) const { Time result = *this; result.minutes += addMinutes; result.hours += result.minutes / 60; result.minutes %= 60; return result; } }; struct BusStop { std::string name; double fare; int time; Time departureTime; BusStop() : fare(0.0), time(0) {} }; struct RouteInfo { int transfers; int time; std::vector<std::string> path; }; class BusSystem { public: void initSystem(const std::string& filename); void addBusStop(const BusStop& stop, int routeNumber); void removeBusStop(const std::string& stopName, int routeNumber); void modifyBusStop(const std::string& stopName, const BusStop& newStop, int routeNumber); void queryRoute(int routeNumber); void queryTransfer(const std::string& start, const std::string& end); void planTour(); void displayRoutes(); void printBusStopsSize() const; void printStopToRoutesSize() const; private: std::vector<std::vector<BusStop> > busStops; std::map<std::string, std::vector<std::pair<int, int> > > stopToRoutes; void loadBusData(const std::string& filename); void saveBusData(const std::string& filename); int getTimeBetweenStops(int route, int start, int end); std::vector<int> findOptimalTourOrder(const std::vector<std::string>& attractions, Time startTime); RouteInfo findShortestPath(const std::string& from, const std::string& to, Time startTime); Time parseTime(const std::string& timeStr); void printDebugInfo() const; }; #endif详细分析
理解问题// BusSystem.h #ifndef BUSSYSTEM_H #define BUSSYSTEM_H #include <vector> #include <string> #include <map> struct Time { int hours; int minutes; Time(int h = 0, int m = 0) : hours(h), minutes(m) {} bool operator<(const Time& other) const { return hours < other.hours || (hours == other.hours && minutes < other.minutes); } bool operator<=(const Time& other) const { return *this < other || *this == other; } bool operator==(const Time& other) const { return hours == other.hours && minutes == other.minutes; } Time operator+(int addMinutes) const { Time result = *this; result.minutes += addMinutes; result.hours += result.minutes / 60; result.minutes %= 60; return result; } }; struct BusStop { std::string name; double fare; int time; Time departureTime; BusStop() : fare(0.0), time(0) {} }; struct RouteInfo { int transfers; int time; std::vector<std::string> path; }; class BusSystem { public: void initSystem(const std::string& filename); void addBusStop(const BusStop& stop, int routeNumber); void removeBusStop(const std::string& stopName, int routeNumber); void modifyBusStop(const std::string& stopName, const BusStop& newStop, int routeNumber); void queryRoute(int routeNumber); void queryTransfer(const std::string& start, const std::string& end); void planTour(); void displayRoutes(); void printBusStopsSize() const; void printStopToRoutesSize() const; private: std::vector<std::vector<BusStop> > busStops; std::map<std::string, std::vector<std::pair<int, int> > > stopToRoutes; void loadBusData(const std::string& filename); void saveBusData(const std::string& filename); int getTimeBetweenStops(int route, int start, int end); std::vector<int> findOptimalTourOrder(const std::vector<std::string>& attractions, Time startTime); RouteInfo findShortestPath(const std::string& from, const std::string& to, Time startTime); Time parseTime(const std::string& timeStr); void printDebugInfo() const; }; #endif详细分析
已完成理解「// BusSystem.h #ifndef BUSSYSTEM_H #define BUSSYSTEM_H #include <vector> #include <string> #include <map> struct Time { int hours; int minutes; Time(int h = 0, int m = 0) : hours(h), minutes(m) {} bool operator<(const Time& other) const { return hours < other.hours || (hours == other.hours && minutes < other.minutes); } bool operator<=(const Time& other) const { return *this < other || *this == other; } bool operator==(const Time& other) const { return hours == other.hours && minutes == other.minutes; } Time operator+(int addMinutes) const { Time result = *this; result.minutes += addMinutes; result.hours += result.minutes / 60; result.minutes %= 60; return result; } }; struct BusStop { std::string name; double fare; int time; Time departureTime; BusStop() : fare(0.0), time(0) {} }; struct RouteInfo { int transfers; int time; std::vector<std::string> path; }; class BusSystem { public: void initSystem(const std::string& filename); void addBusStop(const BusStop& stop, int routeNumber); void removeBusStop(const std::string& stopName, int routeNumber); void modifyBusStop(const std::string& stopName, const BusStop& newStop, int routeNumber); void queryRoute(int routeNumber); void queryTransfer(const std::string& start, const std::string& end); void planTour(); void displayRoutes(); void printBusStopsSize() const; void printStopToRoutesSize() const; private: std::vector<std::vector<BusStop> > busStops; std::map<std::string, std::vector<std::pair<int, int> > > stopToRoutes; void loadBusData(const std::string& filename); void saveBusData(const std::string& filename); int getTimeBetweenStops(int route, int start, int end); std::vector<int> findOptimalTourOrder(const std::vector<std::string>& attractions, Time startTime); RouteInfo findShortestPath(const std::string& from, const std::string& to, Time startTime); Time parseTime(const std::string& timeStr); void printDebugInfo() const; }; #endif详细分析」
展开阅读网页