Advertisement
Guest User

Fashion Boutique

a guest
May 20th, 2019
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. namespace P05FashionBoutique
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class StartUp
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int[] clothes = Console.ReadLine()
  12.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             Stack<int> stack = new Stack<int>(clothes);
  16.             int capacity = int.Parse(Console.ReadLine());
  17.             int sum = 0;
  18.             int numberOfRacks = 1;
  19.             if (stack.Sum() == 0)
  20.             {
  21.                 Console.WriteLine("0");
  22.                 return;
  23.             }
  24.             while (sum < capacity && stack.Count > 0)
  25.             {
  26.                 sum += stack.Peek();
  27.                 if (sum == capacity && stack.Count > 0)
  28.                 {
  29.                     numberOfRacks++;
  30.                     sum = 0;
  31.                 }
  32.                 else if (sum == capacity && stack.Count == 0)
  33.                 {
  34.                     break;
  35.                 }
  36.                 else if (sum > capacity)
  37.                 {
  38.                     numberOfRacks++;
  39.                     sum = stack.Pop();
  40.                     continue;
  41.                 }
  42.                 stack.Pop();
  43.             }
  44.             Console.WriteLine(numberOfRacks);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement