Advertisement
svetlyoek

Untitled

May 22nd, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Cups_and_bottles
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var cupsCapacity = Console.ReadLine().Split().Select(int.Parse);
  12. var bottlesCapacity = Console.ReadLine().Split().Select(int.Parse);
  13.  
  14. var cups = new Queue<int>(cupsCapacity);
  15. var bottles = new Stack<int>(bottlesCapacity);
  16. var loosedWater = 0;
  17. var currentCup = 0;
  18.  
  19. while (true)
  20. {
  21. if (cups.Count == 0)
  22. {
  23. Console.WriteLine($"Bottles: {string.Join(" ", bottles)}");
  24. Console.WriteLine($"Wasted litters of water: {loosedWater}");
  25. return;
  26. }
  27. else if (bottles.Count == 0)
  28. {
  29. Console.WriteLine($"Cups: {string.Join(" ", cups)}");
  30. Console.WriteLine($"Wasted litters of water: {loosedWater}");
  31. return;
  32. }
  33. if (currentCup <= 0)
  34. {
  35. currentCup = cups.Peek();
  36. }
  37.  
  38. if (bottles.Peek() <= currentCup)
  39. {
  40. currentCup -= bottles.Pop();
  41. if (currentCup <= 0)
  42. {
  43. cups.Dequeue();
  44. }
  45. }
  46. else
  47. {
  48. loosedWater += bottles.Peek() - currentCup;
  49. currentCup -= bottles.Pop();
  50. cups.Dequeue();
  51. }
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement