Advertisement
Guest User

Untitled

a guest
Jun 8th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace FashionBoutique
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] clothValues = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.  
  13. int racks = 0;
  14.  
  15. int sum = 0;
  16.  
  17. int capacity = int.Parse(Console.ReadLine());
  18.  
  19. Stack<int> box = new Stack<int>();
  20.  
  21. foreach (var cloth in clothValues)
  22. {
  23. box.Push(cloth);
  24. }
  25.  
  26. while (box.Count > 0)
  27. {
  28. sum = sum + box.Pop();
  29.  
  30. if (sum < capacity)
  31. {
  32. continue;
  33. }
  34. else if (sum == capacity)
  35. {
  36. racks += 1;
  37. sum = box.Pop();
  38. }
  39. else if (sum > capacity)
  40. {
  41. racks += 2;
  42. sum = box.Pop();
  43. }
  44. }
  45. Console.WriteLine(racks);
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement