Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "parking.h"
- using namespace std;
- void puts_car_on_the_parking(parking &parking, int number_of_cars, int level = 1)
- {
- if (level > number_of_cars)
- {
- if (parking.get_number_of_cars_in_the_parking() == number_of_cars)
- {
- cout << '\n' << parking << '\n';
- }
- }
- else
- {
- for (int i = 1; i <= parking.get_size(); ++i)
- {
- parking.add(i, car(level, i));
- puts_car_on_the_parking(parking, number_of_cars, level + 1);
- parking.erase(car(level, i));
- }
- }
- }
- int main()
- {
- int number_of_cars;
- int number_of_parking_spaces;
- cout << "Input number of cars: ";
- cin >> number_of_cars;
- cout << "Input number of parking spaces: ";
- cin >> number_of_parking_spaces;
- if (number_of_cars > number_of_parking_spaces)
- {
- cout << "Empty set (Dirichlet's principle)\n";
- }
- else
- {
- parking parking_0(number_of_parking_spaces);
- puts_car_on_the_parking(parking_0, number_of_cars);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement