Krasimir_Slavov

Untitled

Aug 13th, 2019
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace SummerCocktails
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] ingredientsValues = Console.ReadLine()
  12.                                      .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                                      .Select(int.Parse)
  14.                                      .ToArray();
  15.  
  16.             int[] freshnessValues = Console.ReadLine()
  17.                                    .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  18.                                    .Select(int.Parse)
  19.                                    .ToArray();
  20.  
  21.             Queue<int> ingredients = new Queue<int>(ingredientsValues);
  22.             Stack<int> freshnessLevel = new Stack<int>(freshnessValues);
  23.  
  24.             Dictionary<int, string> advancedMaterials = new Dictionary<int, string>()
  25.             {
  26.                 { 150,"Mimosa" },
  27.                 { 250,"Daiquiri" },
  28.                 { 300,"Sunshine" },
  29.                 { 400,"Mojito" }
  30.             };
  31.             Dictionary<string, int> cocktailName = new Dictionary<string, int>()
  32.             {
  33.                 {"Mimosa", 0 },
  34.                 {"Daiquiri", 0 },
  35.                 {"Sunshine", 0 },
  36.                 {"Mojito", 0 }
  37.             };
  38.             while (ingredients.Count > 0 && freshnessLevel.Count > 0)
  39.             {
  40.                 int liquidValue = ingredients.Dequeue();
  41.                 int freshValue = freshnessLevel.Peek();
  42.                 int sum = liquidValue + freshValue;
  43.                 if (advancedMaterials.ContainsKey(sum))
  44.                 {
  45.                     freshnessLevel.Pop();
  46.                     string newMaterial = advancedMaterials[sum];
  47.  
  48.                     if (!cocktailName.ContainsKey(newMaterial))
  49.                     {
  50.                         cocktailName[newMaterial] = 0;
  51.                     }
  52.                     cocktailName[newMaterial]++;
  53.                 }
  54.                 else
  55.                 {
  56.                     freshnessLevel.Pop();
  57.                     freshnessLevel.Push(freshValue + 5);
  58.                 }
  59.             }
  60.  
  61.             bool canBild = true;
  62.             foreach (var part in cocktailName)
  63.             {
  64.                 foreach (var item in advancedMaterials)
  65.                 {
  66.                     if (part.Value <= 0 && item.Key <= 0)
  67.                     {
  68.                         canBild = false;
  69.                         break;
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             if (canBild)
  75.             {
  76.                 Console.WriteLine($"It's party time! The cocktails are ready!");
  77.             }
  78.             else
  79.             {
  80.                 Console.WriteLine("What a pity! You didn't manage to prepare all cocktails.");
  81.             }
  82.  
  83.             if (ingredients.Count <= 0)
  84.             {
  85.                 int sum = ingredientsValues.Length + freshnessValues.Length;
  86.  
  87.                 Console.WriteLine($"Ingredients left: {sum}");
  88.             }
  89.  
  90.             if (freshnessLevel.Count <= 0)
  91.             {
  92.                 int sum = ingredientsValues.Length + freshnessValues.Length;
  93.  
  94.                 Console.WriteLine($"Freshness values left: {sum}");
  95.             }
  96.  
  97.             foreach (var (key, value) in cocktailName.OrderBy(p => p.Key))
  98.             {
  99.                 Console.WriteLine($" # {key} --> {value}");
  100.             }
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment