Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _1._Santa_s_Present_Factory
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stack<int> myStackMaterials = new Stack<int>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList());
- Queue<int> myQueueMagicLevel = new Queue<int>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList());
- Dictionary<string, int> myDictionary = new Dictionary<string, int>();
- while (myStackMaterials.Count > 0 && myQueueMagicLevel.Count > 0)
- {
- if (myStackMaterials.Peek() == 0 || myQueueMagicLevel.Peek() == 0)
- {
- if (myStackMaterials.Peek() == 0)
- {
- myStackMaterials.Pop();
- }
- if (myQueueMagicLevel.Peek() == 0)
- {
- myQueueMagicLevel.Dequeue();
- }
- continue;
- }
- int result = myStackMaterials.Peek() * myQueueMagicLevel.Peek();
- if (result > 0)
- {
- switch (result)
- {
- case 150:
- if (myDictionary.ContainsKey("Doll"))
- {
- myDictionary["Doll"] += 1;
- }
- else
- {
- myDictionary.Add("Doll", 1);
- }
- myStackMaterials.Pop();
- myQueueMagicLevel.Dequeue();
- break;
- case 250:
- if (myDictionary.ContainsKey("Wooden train"))
- {
- myDictionary["Wooden train"] += 1;
- }
- else
- {
- myDictionary.Add("Wooden train", 1);
- }
- myStackMaterials.Pop();
- myQueueMagicLevel.Dequeue();
- break;
- case 300:
- if (myDictionary.ContainsKey("Teddy bear"))
- {
- myDictionary["Teddy bear"] += 1;
- }
- else
- {
- myDictionary.Add("Teddy bear", 1);
- }
- myStackMaterials.Pop();
- myQueueMagicLevel.Dequeue();
- break;
- case 400:
- if (myDictionary.ContainsKey("Bicycle"))
- {
- myDictionary["Bicycle"] += 1;
- }
- else
- {
- myDictionary.Add("Bicycle", 1);
- }
- myStackMaterials.Pop();
- myQueueMagicLevel.Dequeue();
- break;
- default:
- int tempMaterialValue = myStackMaterials.Pop() + 15;
- myStackMaterials.Push(tempMaterialValue);
- myQueueMagicLevel.Dequeue();
- break;
- }
- }
- else if (result < 0)
- {
- int sum = myStackMaterials.Pop() + myQueueMagicLevel.Dequeue();
- myStackMaterials.Push(sum);
- }
- }
- if ((myDictionary.ContainsKey("Doll") && myDictionary.ContainsKey("Wooden train")) || (myDictionary.ContainsKey("Teddy bear") && myDictionary.ContainsKey("Bicycle")))
- {
- Console.WriteLine($"The presents are crafted! Merry Christmas!");
- }
- else
- {
- Console.WriteLine("No presents this Christmas!");
- }
- if (myStackMaterials.Count > 0)
- {
- Console.WriteLine("Materials left: " + string.Join(", ", myStackMaterials).ToString());
- }
- if (myQueueMagicLevel.Count > 0)
- {
- Console.WriteLine("Magic left: " + string.Join(", ", myQueueMagicLevel).ToString());
- }
- myDictionary = myDictionary.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
- foreach (var item in myDictionary)
- {
- Console.WriteLine($"{item.Key}: {item.Value}".ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement