Advertisement
Guest User

Untitled

a guest
Mar 18th, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 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 cups = Console.ReadLine().Split().Select(int.Parse).Reverse();
  12. var bottles = Console.ReadLine().Split().Select(int.Parse);
  13.  
  14. var cupsStack = new Stack<int>(cups);
  15. var bottlesStack = new Stack<int>(bottles);
  16. var wastedLiters = 0;
  17.  
  18. while (cupsStack.Count != 0 && bottlesStack.Count != 0)
  19. {
  20.  
  21. //Console.WriteLine(cupsStack.Peek() + " cups");
  22. //Console.WriteLine(bottlesStack.Peek() + " bottles");
  23.  
  24. var bottleSize = bottlesStack.Pop();
  25. var cupSize = cupsStack.Pop();
  26.  
  27.  
  28. if (cupSize > bottleSize)
  29. {
  30. var fillUp = cupSize - bottleSize;
  31. cupsStack.Push(fillUp);
  32. }
  33. else
  34. {
  35. wastedLiters += bottleSize - cupSize;
  36. }
  37. }
  38.  
  39. if(bottlesStack.Count != 0)
  40. {
  41. Console.WriteLine($"Bottles: {string.Join(" ", bottlesStack)}");
  42. Console.WriteLine($"Wasted litters of water: {wastedLiters}");
  43. }
  44. else
  45. {
  46.  
  47. Console.WriteLine($"Cups: {string.Join(" ", cupsStack)}");
  48. Console.WriteLine($"Wasted litters of water: {wastedLiters}");
  49. }
  50.  
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement