Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include "parking.h"
  2.  
  3. using namespace std;
  4.  
  5. void puts_car_on_the_parking(parking &parking, int number_of_cars, int level = 1)
  6. {
  7.     if (level > number_of_cars)
  8.     {
  9.         if (parking.get_number_of_cars_in_the_parking() == number_of_cars)
  10.         {
  11.             cout << '\n' << parking << '\n';
  12.         }
  13.     }
  14.     else
  15.     {
  16.         for (int i = 1; i <= parking.get_size(); ++i)
  17.         {
  18.             parking.add(i, car(level, i));
  19.             puts_car_on_the_parking(parking, number_of_cars, level + 1);
  20.             parking.erase(car(level, i));
  21.         }
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     int number_of_cars;
  28.     int number_of_parking_spaces;
  29.  
  30.     cout << "Input number of cars: ";
  31.     cin >> number_of_cars;
  32.     cout << "Input number of parking spaces: ";
  33.     cin >> number_of_parking_spaces;
  34.  
  35.     if (number_of_cars > number_of_parking_spaces)
  36.     {
  37.         cout << "Empty set (Dirichlet's principle)\n";
  38.     }
  39.     else
  40.     {
  41.         parking parking_0(number_of_parking_spaces);
  42.  
  43.         puts_car_on_the_parking(parking_0, number_of_cars);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement