Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstring>
- #include <fstream>
- #include <cstdio>
- #include <cmath>
- using namespace std;
- //ПЕРСОНАЛЬНО НАЙДУ И ВЫРЕЖУ ГОРЛО ТОМУ, КТО СПИШЕТ НИКАК НЕ ИЗМЕНИВ КОД
- class Room {
- int capacity; // Количество гостей, на которое комната рассчитана
- bool occupied; // Занята ли комната
- public:
- Room(int capacity = 1, bool occupied = false);
- Room(const Room& tmp);
- bool is_occupied(){return occupied;} // Метод, который позволяет узнать, занята ли комната
- int get_capacity(){return capacity;} // Метод, который получает количество гостей, которые умещаются в комнату
- void reserve(){this->occupied = 1;} // Занять номер
- void free(){this->occupied = 0;} // Освободить номер
- };
- Room::Room(int capacity, bool occupied){
- cin >> capacity;
- this->capacity = capacity;
- this->occupied = occupied;
- }
- Room::Room(const Room &tmp){
- this->capacity = tmp.capacity;
- this->occupied = tmp.occupied;
- }
- //------------------------
- class Hotel {
- int room_count;
- Room* rooms; // Дин. массив комнат
- public:
- Hotel(int room_count);
- Hotel(const Hotel &tmp);
- ~Hotel();
- void free_room(int num){this->rooms[num].free();}
- int get_room_count(){return room_count;} // Узнать количество комнат
- Room& get_room(int p); // Получить комнату под номером p
- int count_free(); // Подсчитать количество свободных комнат
- int find_room(int k); // Найти комнату ровно на k гостей
- };
- Hotel::Hotel(int room_count){
- this->room_count = room_count;
- this->rooms = new Room[this->room_count];
- for (int i = 0; i < room_count; ++i){
- rooms[i].free();
- }
- }
- Hotel::Hotel(const Hotel &tmp){
- for (int i = 0; i < this->room_count; ++i){
- this->rooms[i] = tmp.rooms[i];
- }
- this->room_count = tmp.room_count;
- }
- Hotel::~Hotel(){
- delete [] rooms;
- }
- Room& Hotel::get_room(int p){
- return rooms[p];
- }
- int Hotel::count_free(){
- int count = 0;
- for (int i = 0; i < room_count; ++i){
- if (!rooms[i].is_occupied())
- ++count;
- }
- return count;
- }
- int Hotel::find_room(int k){
- for (int i = 0; i < room_count; ++i){
- if (!rooms[i].is_occupied() && rooms[i].get_capacity() == k){
- rooms[i].reserve();
- return i;
- }
- }
- return -1;
- }
- int main() {
- int n, rooms;
- cin >>rooms;
- Hotel a(rooms);
- cin >> n;
- for (int i = 0; i < n; ++i){
- char command[8] = {};
- cin >> command;
- if (!strcmp(command, "RESERVE")){
- int ppl;
- cin >> ppl;
- cout << a.find_room(ppl) << endl;
- }
- if (!strcmp(command, "FREE")){
- int num;
- cin >> num;
- a.free_room(num);
- }
- if (!strcmp(command, "STATUS")){
- cout << a.count_free() << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement