Advertisement
desislava_topuzakova

05. Fashion Boutique

May 17th, 2022
818
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.Generic;
  3. using System.Linq;
  4.  
  5. namespace FashionBoutique
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] inputValues = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int rackCapacity = int.Parse(Console.ReadLine());
  13.  
  14.             Stack<int> clothesValues = new Stack<int>(inputValues);
  15.  
  16.             int racks = 1;
  17.             int sum = 0;
  18.  
  19.             while (clothesValues.Any())
  20.             {
  21.                 if (sum + clothesValues.Peek() <= rackCapacity)
  22.                 {
  23.                     sum += clothesValues.Pop();
  24.                 }
  25.                 else
  26.                 {
  27.                     sum = 0;
  28.                     racks++;
  29.                 }
  30.             }
  31.             Console.WriteLine(racks);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement