Advertisement
Guest User

Untitled

a guest
Sep 27th, 2021
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.Masterchef
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] ingridientsInput = Console.ReadLine()
  12.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             int[] freshnessInput = Console.ReadLine()
  16.               .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  17.               .Select(int.Parse)
  18.               .ToArray();
  19.  
  20.             Queue<int> ingridients = new Queue<int>(ingridientsInput);
  21.             Stack<int> freshness = new Stack<int>(freshnessInput);
  22.  
  23.             int dippingSauce = 0;
  24.             int greenSalad = 0;
  25.             int chocolateCake = 0;
  26.             int lobster = 0;
  27.  
  28.  
  29.  
  30.             SortedDictionary<string, int> preparedDishes = new SortedDictionary<string, int>()
  31.             {
  32.                 {"Dipping sauce",dippingSauce},
  33.                 {"Green salad",greenSalad},
  34.                 {"Chocolate cake",chocolateCake},
  35.                 {"Lobster",lobster}
  36.  
  37.             };
  38.  
  39.             while (ingridients.Any() && freshness.Any())
  40.             {
  41.                 int currentIngidient = ingridients.Peek();
  42.                 int currentFreshness = freshness.Peek();
  43.  
  44.                 if (currentIngidient == 0)
  45.                 {
  46.                     ingridients.Dequeue();
  47.                     continue;
  48.  
  49.                 }
  50.  
  51.                 if (currentIngidient * currentFreshness == 150)
  52.                 {
  53.                     ingridients.Dequeue();
  54.                     freshness.Pop();
  55.                     preparedDishes["Dipping sauce"]++;
  56.                     dippingSauce++;
  57.                 }
  58.                 else if (currentIngidient * currentFreshness == 250)
  59.                 {
  60.                     ingridients.Dequeue();
  61.                     freshness.Pop();
  62.                     preparedDishes["Green salad"]++;
  63.                     greenSalad++;
  64.                 }
  65.                 else if (currentIngidient * currentFreshness == 300)
  66.                 {
  67.                     ingridients.Dequeue();
  68.                     freshness.Pop();
  69.                     preparedDishes["Chocolate cake"]++;
  70.                     chocolateCake++;
  71.                 }
  72.                 else if (currentIngidient * currentFreshness == 400)
  73.                 {
  74.                     ingridients.Dequeue();
  75.                     freshness.Pop();
  76.                     preparedDishes["Lobster"]++;
  77.                     lobster++;
  78.                 }
  79.  
  80.                 else
  81.                 {
  82.                     freshness.Pop();
  83.                     currentIngidient += 5;
  84.                     ingridients.Enqueue(currentIngidient);
  85.                     ingridients.Dequeue();
  86.                 }
  87.  
  88.             }
  89.             bool succes = dippingSauce >= 1 && greenSalad >= 1 && chocolateCake >= 1 && lobster >= 1;
  90.             var sum = ingridients.Sum();
  91.             if (succes)
  92.             {
  93.  
  94.                 Console.WriteLine("Applause! The judges are fascinated by your dishes! ");
  95.                 if (sum != 0)
  96.                 {
  97.                     Console.WriteLine($"Ingredients left: {sum}");
  98.                 }
  99.                 foreach (var dish in preparedDishes)
  100.                 {
  101.                     Console.WriteLine($" # {dish.Key} --> {dish.Value}");
  102.                 }
  103.  
  104.             }
  105.             else
  106.             {
  107.                 Console.WriteLine("You were voted off. Better luck next year.");
  108.                 if (sum != 0)
  109.                 {
  110.                     Console.WriteLine($"Ingredients left: {sum}");
  111.                 }
  112.                 foreach (var dish in preparedDishes)
  113.                 {
  114.                     if (dish.Value > 0)
  115.                     {
  116.                         Console.WriteLine($" # {dish.Key} --> {dish.Value}");
  117.                     }
  118.  
  119.                 }
  120.  
  121.             }
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement