Advertisement
Spocoman

05. Fashion Boutique

Jan 12th, 2024
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <stack>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string line;
  10.     getline(cin, line);
  11.  
  12.     int quantity, dress, racks = 1, sum = 0;
  13.     cin >> quantity;
  14.  
  15.     stack<int> clothes;
  16.  
  17.     istringstream ss(line);
  18.  
  19.     while (ss >> dress) {
  20.         clothes.push(dress);
  21.     }
  22.  
  23.     while (!clothes.empty()) {
  24.         sum += clothes.top();
  25.         if (sum <= quantity) {
  26.             clothes.pop();
  27.         }
  28.         else {
  29.             racks++;
  30.             sum = 0;
  31.         }
  32.     }
  33.  
  34.     cout << racks << endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement