gabi11

Stacks and Queues - 05. Fashion Boutique

May 10th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace Advanced
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var stackOfClothes = new Stack<int>(Console.ReadLine().Split().Select(int.Parse));
  13.             int rackCapacity = int.Parse(Console.ReadLine());
  14.  
  15.             int sumValue = 0;
  16.             int countRacks = 1;
  17.  
  18.             while (stackOfClothes.Any())
  19.             {
  20.                 if (sumValue + stackOfClothes.Peek() <= rackCapacity)
  21.                 {
  22.                     sumValue += stackOfClothes.Pop();
  23.                 }
  24.  
  25.                 else
  26.                 {
  27.                     sumValue = 0;
  28.                     countRacks++;
  29.                 }
  30.             }
  31.  
  32.             Console.WriteLine(countRacks);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment