Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2021
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 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[] quantityOfClothes = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13.             int capacityOfRack = int.Parse(Console.ReadLine());
  14.  
  15.             Stack<int> clothesStack = new Stack<int>(quantityOfClothes);
  16.  
  17.             int countRack = 1;
  18.             int sumClothes = 0;
  19.  
  20.             //if (clothesStack.Sum() == 0 || capacityOfRack == 0)
  21.             //{
  22.             //    countRack = 0;
  23.             //    Console.WriteLine(countRack);
  24.             //    return;
  25.             //}
  26.  
  27.             while (clothesStack.Count > 0)
  28.             {
  29.                 var currElement = clothesStack.Pop(); //взимаш стойността на последния елемент
  30.                 if (sumClothes + currElement <= capacityOfRack)     //проверяваш дали няма да се препълни ако я добавиш
  31.                 {
  32.                     sumClothes += currElement;                  //добавяш към сумата
  33.                 }
  34.                 else
  35.                 {
  36.                     sumClothes = currElement;       //новата сума за новия рафт трябва да е равна на елемента, който добавяме като първи на рафта
  37.                     countRack++;
  38.                 }
  39.             }
  40.  
  41.             //if (sumClothes > 0 && countRack > 1) //не виждам никаква логика в това
  42.             //{                                    //
  43.             //    countRack++;                     //
  44.             //}                                    //
  45.  
  46.             Console.WriteLine(countRack);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement