Advertisement
svetlyoek

new

Aug 13th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SummerCocktails
  6. {
  7. public class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] ingredientsValue = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToArray();
  15.  
  16. int[] freshnessValue = Console.ReadLine()
  17. .Split()
  18. .Select(int.Parse)
  19. .ToArray();
  20.  
  21. int mimossa = 150;
  22. int daiquiri = 250;
  23. int sunshine = 300;
  24. int mojito = 400;
  25.  
  26. int sum = 0;
  27. int totalFreshness = 0;
  28.  
  29. Dictionary<string, int> productsToCreate = new Dictionary<string, int>();
  30.  
  31. productsToCreate.Add("Mimosa", 0);
  32. productsToCreate.Add("Daiquiri", 0);
  33. productsToCreate.Add("Sunshine", 0);
  34. productsToCreate.Add("Mojito", 0);
  35.  
  36. Queue<int> ingredients = new Queue<int>(ingredientsValue);
  37.  
  38. Stack<int> freshness = new Stack<int>(freshnessValue);
  39.  
  40. while (true)
  41. {
  42. if (ingredients.Count == 0 || freshness.Count == 0)
  43. {
  44. break;
  45. }
  46.  
  47. var currentIngredient = ingredients.Peek();
  48. var currentFreshness = freshness.Peek();
  49.  
  50. totalFreshness = currentIngredient * currentFreshness;
  51.  
  52. if (currentIngredient == 0)
  53. {
  54. ingredients.Dequeue();
  55. continue;
  56. }
  57.  
  58. if (totalFreshness == mimossa)
  59. {
  60. productsToCreate["Mimosa"]++;
  61. ingredients.Dequeue();
  62. freshness.Pop();
  63. }
  64.  
  65. else if (totalFreshness == daiquiri)
  66. {
  67. productsToCreate["Daiquiri"]++;
  68. ingredients.Dequeue();
  69. freshness.Pop();
  70. }
  71.  
  72. else if (totalFreshness == sunshine)
  73. {
  74. productsToCreate["Sunshine"]++;
  75. ingredients.Dequeue();
  76. freshness.Pop();
  77. }
  78.  
  79. else if (totalFreshness == mojito)
  80. {
  81. productsToCreate["Mojito"]++;
  82. ingredients.Dequeue();
  83. freshness.Pop();
  84. }
  85.  
  86. else
  87. {
  88. freshness.Pop();
  89. int newIngredient = currentIngredient + 5;
  90. ingredients.Dequeue();
  91. ingredients.Enqueue(newIngredient);
  92. }
  93.  
  94. totalFreshness = 0;
  95. }
  96.  
  97. if (productsToCreate["Mimosa"] > 0 && productsToCreate["Daiquiri"] > 0 && productsToCreate["Sunshine"] > 0 && productsToCreate["Mojito"] > 0)
  98. {
  99. Console.WriteLine("It's party time! The cocktails are ready!");
  100. }
  101. else
  102. {
  103. Console.WriteLine("What a pity! You didn't manage to prepare all cocktails.");
  104. }
  105.  
  106. if (ingredients.Any())
  107. {
  108. foreach (var ingredient in ingredients)
  109. {
  110. sum += ingredient;
  111. }
  112.  
  113. Console.WriteLine($"Ingredients left: {sum}");
  114. }
  115.  
  116. foreach (var cocktail in productsToCreate.OrderBy(x => x.Key))
  117. {
  118. if (cocktail.Value > 0)
  119. {
  120. Console.WriteLine($" # {cocktail.Key} --> {cocktail.Value}");
  121. }
  122. }
  123.  
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement