kirililchev3

Fashion Boutique

Jan 16th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Fashion_Boutique
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] clothesInBox = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int capacityOfRack = int.Parse(Console.ReadLine());
  13.             var stack = new Stack<int>(clothesInBox);
  14.             int countOfRack = 1;
  15.             int sum = 0;
  16.  
  17.             while (stack.Count > 0)
  18.             {
  19.                 if (sum < capacityOfRack)
  20.                 {
  21.                     sum += stack.Pop();
  22.                    
  23.                     if (sum == capacityOfRack)
  24.                     {
  25.                         countOfRack++;
  26.                         sum = 0;
  27.                     }
  28.  
  29.                     else if (sum > capacityOfRack)
  30.                     {
  31.                         countOfRack++;
  32.                         sum = 0;
  33.                     }
  34.                 }
  35.  
  36.                
  37.             }
  38.  
  39.             Console.WriteLine(countOfRack);
  40.  
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment