Advertisement
cska1312

05. Fashion Boutique

May 10th, 2023 (edited)
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3. #include <stack>
  4. #include <string>
  5. #include <vector>
  6. #include <sstream>
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12.   string buffer;
  13.   getline(cin, buffer);
  14.   istringstream istr(buffer);
  15.  
  16.   stack<int> pile;
  17.   int curElt;
  18.   while(istr >> curElt)
  19.     pile.push(curElt);
  20.  
  21.   int rackSize;
  22.   cin >> rackSize;
  23.  
  24.   int racks = 1;
  25.   int curRackSize = rackSize;
  26.  
  27.   while(pile.size())
  28.     {
  29.       int curPiece = pile.top();
  30.       pile.pop();
  31.  
  32.       if(curPiece <= curRackSize)
  33.       {
  34.         curRackSize -= curPiece;
  35.       }else{
  36.         //initialize new rack
  37.         racks++;
  38.         curRackSize = rackSize;
  39.  
  40.         //put the piece on the rack
  41.         curRackSize -= curPiece;
  42.       }
  43.     }
  44.     cout << racks << endl;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement