Advertisement
Prohause

Exam 14010.2018 Problem 04

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