2023-05-30 00:02:00 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
class ParkingSystem {
|
|
|
|
int big;
|
|
|
|
int medium;
|
|
|
|
int small;
|
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
int &get(int carType) {
|
2023-05-30 00:02:00 +02:00
|
|
|
switch (carType) {
|
|
|
|
case 1:
|
|
|
|
return big;
|
|
|
|
case 2:
|
|
|
|
return medium;
|
|
|
|
case 3:
|
|
|
|
return small;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
public:
|
2023-05-30 00:02:00 +02:00
|
|
|
ParkingSystem(int big, int medium, int small)
|
2024-01-03 12:06:42 +01:00
|
|
|
: big(big), medium(medium), small(small) {}
|
2023-05-30 00:02:00 +02:00
|
|
|
|
2024-01-03 12:06:42 +01:00
|
|
|
bool addCar(int carType) {
|
|
|
|
auto &space = get(carType);
|
2023-05-30 00:02:00 +02:00
|
|
|
if (space <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
--space;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Your ParkingSystem object will be instantiated and called as such:
|
|
|
|
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
|
|
|
|
* bool param_1 = obj->addCar(carType);
|
|
|
|
*/
|