Advertisement
Spocoman

02. The Lift

Nov 4th, 2023 (edited)
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int people;
  9.     cin >> people;
  10.     cin.ignore();
  11.  
  12.     string wagonLine;
  13.     getline(cin, wagonLine);
  14.  
  15.     vector<int> wagons;
  16.  
  17.     for (int i = 0; i < wagonLine.length(); i += 2) {
  18.         wagons.push_back(stoi(&wagonLine[i]));
  19.     }
  20.  
  21.     for (int i = 0; i < wagons.size(); i++) {
  22.         for (int j = wagons[i]; j < 4; j++) {
  23.             if (people == 0) {
  24.                 break;
  25.             }
  26.             wagons[i]++;
  27.             people--;
  28.         }
  29.     }
  30.  
  31.     if (wagons[wagons.size() - 1] < 4) {
  32.         cout << "The lift has empty spots!\n";
  33.     }
  34.     else if (people > 0) {
  35.         cout << "There isn't enough space! " << people << " people in a queue!\n";
  36.     }
  37.     for (auto& w : wagons) {
  38.         cout << w << ' ';
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement