Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace T01_Masterchef
- {
- class Program
- {
- static void Main(string[] args)
- {
- Queue<int> ingredient = new Queue<int>(Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray());
- Stack<int> freshnessLevel = new Stack<int>(Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray());
- Dictionary<string, int> dishes = new Dictionary<string, int>();
- dishes.Add("Dipping sauce", 0);
- dishes.Add("Green salad", 0);
- dishes.Add("Chocolate cake", 0);
- dishes.Add("Lobster", 0);
- while (ingredient.Count > 0 && freshnessLevel.Count > 0)
- {
- if (ingredient.Peek() == 0)
- {
- ingredient.Dequeue();
- continue;
- }
- int totalFreshnessLevel = ingredient.Peek() * freshnessLevel.Peek();
- switch (totalFreshnessLevel)
- {
- case 150:
- dishes["Dipping sauce"]++;
- ingredient.Dequeue();
- freshnessLevel.Pop();
- break;
- case 250:
- dishes["Green salad"]++;
- ingredient.Dequeue();
- freshnessLevel.Pop();
- break;
- case 300:
- dishes["Chocolate cake"]++;
- ingredient.Dequeue();
- freshnessLevel.Pop();
- break;
- case 400:
- dishes["Lobster"]++;
- ingredient.Dequeue();
- freshnessLevel.Pop();
- break;
- default:
- freshnessLevel.Pop();
- ingredient.Enqueue(ingredient.Dequeue() + 5);
- break;
- }
- }
- var sorted = dishes
- .Where(d => d.Value > 0)
- .OrderBy(d => d.Key)
- .ToDictionary(d => d.Key, d => d.Value);
- if (sorted.Count == 4)
- {
- Console.WriteLine("Applause! The judges are fascinated by your dishes!");
- }
- else
- {
- Console.WriteLine("You were voted off. Better luck next year.");
- }
- if (ingredient.Count > 0)
- {
- Console.WriteLine($"Ingredients left: {ingredient.Sum()}");
- }
- foreach (var kvp in sorted)
- {
- Console.WriteLine($"# {kvp.Key} --> {kvp.Value}");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment