DeeAG

T01.Masterchef

Jun 26th, 2021 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace T01_Masterchef
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Queue<int> ingredient = new Queue<int>(Console.ReadLine()
  12.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray());
  15.  
  16.             Stack<int> freshnessLevel = new Stack<int>(Console.ReadLine()
  17.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  18.                 .Select(int.Parse)
  19.                 .ToArray());
  20.  
  21.             Dictionary<string, int> dishes = new Dictionary<string, int>();
  22.             dishes.Add("Dipping sauce", 0);
  23.             dishes.Add("Green salad", 0);
  24.             dishes.Add("Chocolate cake", 0);
  25.             dishes.Add("Lobster", 0);
  26.  
  27.  
  28.             while (ingredient.Count > 0 && freshnessLevel.Count > 0)
  29.             {
  30.                 if (ingredient.Peek() == 0)
  31.                 {
  32.                     ingredient.Dequeue();
  33.                     continue;
  34.                 }
  35.  
  36.                 int totalFreshnessLevel = ingredient.Peek() * freshnessLevel.Peek();
  37.  
  38.                 switch (totalFreshnessLevel)
  39.                 {
  40.                     case 150:
  41.                         dishes["Dipping sauce"]++;
  42.                         ingredient.Dequeue();
  43.                         freshnessLevel.Pop();
  44.                         break;
  45.  
  46.                     case 250:
  47.                         dishes["Green salad"]++;
  48.                         ingredient.Dequeue();
  49.                         freshnessLevel.Pop();
  50.                         break;
  51.  
  52.                     case 300:
  53.                         dishes["Chocolate cake"]++;
  54.                         ingredient.Dequeue();
  55.                         freshnessLevel.Pop();
  56.                         break;
  57.  
  58.                     case 400:
  59.                         dishes["Lobster"]++;
  60.                         ingredient.Dequeue();
  61.                         freshnessLevel.Pop();
  62.                         break;
  63.  
  64.                     default:
  65.                         freshnessLevel.Pop();
  66.                         ingredient.Enqueue(ingredient.Dequeue() + 5);
  67.                         break;
  68.                 }
  69.             }
  70.  
  71.             var sorted = dishes
  72.                 .Where(d => d.Value > 0)
  73.                 .OrderBy(d => d.Key)
  74.                 .ToDictionary(d => d.Key, d => d.Value);
  75.  
  76.             if (sorted.Count == 4)
  77.             {
  78.                 Console.WriteLine("Applause! The judges are fascinated by your dishes!");
  79.             }
  80.             else
  81.             {
  82.                 Console.WriteLine("You were voted off. Better luck next year.");
  83.             }
  84.  
  85.             if (ingredient.Count > 0)
  86.             {
  87.                 Console.WriteLine($"Ingredients left: {ingredient.Sum()}");
  88.             }
  89.             foreach (var kvp in sorted)
  90.             {
  91.                 Console.WriteLine($"# {kvp.Key} --> {kvp.Value}");
  92.             }
  93.         }
  94.     }
  95. }
Add Comment
Please, Sign In to add comment