Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _05_Fashion_Boutique
- {
- class Program
- {
- static void Main(string[] args)
- {
- var priceOfClothes = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int capacityOfARack = int.Parse(Console.ReadLine());
- Stack<int> prices = new Stack<int>(priceOfClothes);
- int sumOfClothes = 0;
- int numOfRacks = 1;
- //5 4 8 6 3 8 7 7 9 --- orders
- //16 -- capacity
- for (int i = 0; i < priceOfClothes.Length; i++)
- {
- sumOfClothes += priceOfClothes[i];
- if (sumOfClothes == capacityOfARack)
- {
- numOfRacks++;
- sumOfClothes = 0;
- if (prices.Any())
- {
- continue;
- }
- }
- else if (sumOfClothes > capacityOfARack)
- {
- numOfRacks++;
- sumOfClothes = 0;
- i--;
- if (prices.Any())
- {
- continue;
- }
- }
- prices.Pop();
- }
- Console.WriteLine(numOfRacks);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement