Advertisement
Guest User

Untitled

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