Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05._Fashion_Boutique
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12. int rackCapacity = int.Parse(Console.ReadLine());
  13. int rackCounter = 1;
  14.  
  15. Stack<int> clothesValues = new Stack<int>(input);
  16.  
  17. int currentClothesValue = 0;
  18.  
  19. for (int i = 0; i < clothesValues.Count; i++)
  20. {
  21. int currentClothValue = clothesValues.Pop();
  22. if (rackCapacity - (currentClothesValue + currentClothValue) > 0)
  23. {
  24. currentClothesValue += currentClothValue;
  25. i--;
  26. }
  27. else if (rackCapacity - (currentClothesValue + currentClothValue) == 0)
  28. {
  29. if (clothesValues.Count != 0)
  30. {
  31. rackCounter++;
  32. currentClothesValue = 0;
  33. i--;
  34. }
  35. }
  36. else if (rackCapacity - (currentClothesValue + currentClothValue) < 0)
  37. {
  38. clothesValues.Push(currentClothValue);
  39. rackCounter++;
  40. currentClothesValue = 0;
  41. i--;
  42. }
  43. }
  44. Console.WriteLine(rackCounter);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement