Advertisement
Guest User

C++ Red belt booking

a guest
Aug 17th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include "test_runner.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdint>
  5. #include <map>
  6. #include <deque>
  7.  
  8. using namespace std;
  9.  
  10. typedef uint32_t ClientID;
  11. typedef int64_t Time;
  12. typedef uint16_t RoomCount;
  13. typedef string HotelName;
  14.  
  15. const Time hours_24 = 86400;
  16.  
  17. struct InputItem {
  18.     Time time;
  19.     HotelName hotel_name;
  20.     ClientID client_id;
  21.     RoomCount room_count;
  22. };
  23.  
  24. class HotelBase {
  25.  
  26.     typedef map<ClientID, size_t> ClientMap;
  27.     struct HotelItem {
  28.         ClientMap clients;
  29.         size_t reserved_rooms;
  30.     };
  31.     typedef map<HotelName, HotelItem> HotelMap;
  32.  
  33.     struct QueueItem {
  34.         QueueItem(Time time, HotelMap::iterator hotel_it,
  35.                 ClientMap::iterator client_it, RoomCount room_count) :
  36.                 time(time), hotel_it(hotel_it), client_it(client_it), room_count(
  37.                         room_count) {
  38.         }
  39.         Time time;
  40.         HotelMap::iterator hotel_it;
  41.         ClientMap::iterator client_it;
  42.         RoomCount room_count;
  43.     };
  44.  
  45. public:
  46.     void Book(const InputItem& input);
  47.     size_t Clients(const HotelName& hotel_name) const;
  48.     size_t Rooms(const HotelName& hotel_name) const;
  49.  
  50. private:
  51.     HotelMap hotels;
  52.     deque<QueueItem> time_queue;
  53. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement