Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Santa_Present_Factory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] data = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- Stack<int> stack = new Stack<int>(data);
- data = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- Queue<int> queue = new Queue<int>(data);
- Dictionary<string, int> dict = new Dictionary<string, int>();
- dict["Doll"] = 0;
- dict["Wooden train"] = 0;
- dict["Teddy bear"] = 0;
- dict["Bicycle"] = 0;
- while (stack.Count > 0 && queue.Count > 0)
- {
- int currentMaterial = stack.Peek();
- int currentMagic = queue.Peek();
- if (currentMaterial == 0 || currentMagic == 0)
- {
- if (currentMaterial == 0)
- {
- stack.Pop();
- }
- if (currentMagic == 0)
- {
- queue.Dequeue();
- }
- continue;
- }
- int result = currentMaterial * currentMagic;
- queue.Dequeue();
- stack.Pop();
- if (result > 0)
- {
- if (result == 150)
- {
- dict["Doll"]++;
- }
- else if (result == 250)
- {
- dict["Wooden train"]++;
- }
- else if (result == 300)
- {
- dict["Teddy bear"]++;
- }
- else if (result == 400)
- {
- dict["Bicycle"]++;
- }
- else
- {
- stack.Push(currentMaterial + 15);
- }
- }
- else if (result < 0)
- {
- stack.Push(currentMaterial + currentMagic);
- }
- }
- if ((dict["Doll"] >= 1 && dict["Wooden train"] >= 1) || (dict["Teddy bear"] >= 1 && dict["Bicycle"] >= 1))
- {
- Console.WriteLine($"The presents are crafted! Merry Christmas!");
- }
- else
- {
- Console.WriteLine($"No presents this Christmas!");
- }
- if (stack.Count > 0)
- {
- Console.WriteLine($"Materials left: {string.Join(", ", stack)}");
- }
- if (queue.Count > 0)
- {
- Console.WriteLine($"Magic left: {string.Join(", ", queue)}");
- }
- dict
- .OrderBy(x => x.Key)
- .Where(x => x.Value > 0)
- .ToList()
- .ForEach(x => Console.WriteLine($"{x.Key}: {x.Value}"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment