Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SummerCocktails
  6. {
  7. public class Cocktail
  8. {
  9. public string Name { get;}
  10. public int FreshnessLevel { get;}
  11.  
  12. public Cocktail(string name, int fLevel)
  13. {
  14. this.Name = name;
  15. this.FreshnessLevel = fLevel;
  16. }
  17.  
  18. public override bool Equals(object obj)
  19. {
  20. Cocktail other = obj as Cocktail;
  21. if (other == null) return false;
  22. else if (this.FreshnessLevel == other.FreshnessLevel) return true;
  23. return false;
  24. }
  25.  
  26. public override int GetHashCode()
  27. {
  28. return this.FreshnessLevel.ToString().GetHashCode();
  29. }
  30. }
  31.  
  32. class Program
  33. {
  34. static void Main()
  35. {
  36. var cocktailsTable = PopulateCocktailsTable();
  37. var ingredients = new Queue<int>(takeInputIntegers());
  38. var freshness = new Stack<int>(takeInputIntegers());
  39. while(ingredients.Count>0 && freshness.Count>0)
  40. {
  41. var currentIngredient =0;
  42. while (currentIngredient ==0 && ingredients.Count>0)
  43. {
  44. currentIngredient = ingredients.Dequeue();
  45. }
  46. if (currentIngredient > 0)
  47. {
  48. var result = currentIngredient * freshness.Pop();
  49. var searchCocktail = new Cocktail("", result);
  50. if (cocktailsTable.ContainsKey(searchCocktail))
  51. {
  52. cocktailsTable[searchCocktail]++;
  53. }
  54. else ingredients.Enqueue(currentIngredient + 5);
  55. }
  56. }
  57. var sortedCocktails = cocktailsTable.OrderBy(x => x.Key.Name).Where(x => x.Value > 0);
  58. if (sortedCocktails.Count() > 3) Console.WriteLine("It's party time! The cocktails are ready!");
  59. else
  60. {
  61. Console.WriteLine("What a pity! You didn't manage to prepare all cocktails.");
  62. if (ingredients.Count>0) Console.WriteLine($"Ingredients left: {ingredients.Sum()}");
  63. }
  64. foreach(var item in sortedCocktails)
  65. {
  66. Console.WriteLine($" # {item.Key.Name} --> {item.Value}");
  67. }
  68.  
  69. }
  70.  
  71. private static Dictionary<Cocktail,int> PopulateCocktailsTable()
  72. {
  73. var set = new Dictionary<Cocktail,int>();
  74. set.Add(new Cocktail("Mimosa", 150),0);
  75. set.Add(new Cocktail("Daiquiri", 250),0);
  76. set.Add(new Cocktail("Sunshine", 300),0);
  77. set.Add(new Cocktail("Mojito", 400),0);
  78. return set;
  79. }
  80.  
  81. private static IEnumerable<int> takeInputIntegers()
  82. {
  83. return Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement