Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace FashionBoutique
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] quantityOfClothes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int capacityOfRack = int.Parse(Console.ReadLine());
- Stack<int> clothesStack = new Stack<int>(quantityOfClothes);
- int countRack = 1;
- int sumClothes = 0;
- //if (clothesStack.Sum() == 0 || capacityOfRack == 0)
- //{
- // countRack = 0;
- // Console.WriteLine(countRack);
- // return;
- //}
- while (clothesStack.Count > 0)
- {
- var currElement = clothesStack.Pop(); //взимаш стойността на последния елемент
- if (sumClothes + currElement <= capacityOfRack) //проверяваш дали няма да се препълни ако я добавиш
- {
- sumClothes += currElement; //добавяш към сумата
- }
- else
- {
- sumClothes = currElement; //новата сума за новия рафт трябва да е равна на елемента, който добавяме като първи на рафта
- countRack++;
- }
- }
- //if (sumClothes > 0 && countRack > 1) //не виждам никаква логика в това
- //{ //
- // countRack++; //
- //} //
- Console.WriteLine(countRack);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement