Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CSh_Advanced_Retake_Exam___17_December_2019
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] materialsValues = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[] magicValues = Console.ReadLine().Split().Select(int.Parse).ToArray();
- Stack<int> materials = new Stack<int>();
- Queue<int> magic = new Queue<int>();
- Dictionary<string, int> presents = new Dictionary<string, int>();
- presents["Doll"] = 0;
- presents["Wooden train"] = 0;
- presents["Teddy bear"] = 0;
- presents["Bicycle"] = 0;
- foreach (var number in materialsValues)
- {
- materials.Push(number);
- }
- foreach (var number in magicValues)
- {
- magic.Enqueue(number);
- }
- while (true)
- {
- if (materials.Count <= 0 || magic.Count <= 0)
- {
- break;
- }
- int current = materials.Peek() * magic.Peek();
- switch (current)
- {
- case 150:
- materials.Pop();
- magic.Dequeue();
- presents["Doll"]++;
- break;
- case 250:
- materials.Pop();
- magic.Dequeue();
- presents["Wooden train"]++;
- break;
- case 300:
- materials.Pop();
- magic.Dequeue();
- presents["Teddy bear"]++;
- break;
- case 400:
- materials.Pop();
- magic.Dequeue();
- presents["Bicycle"]++;
- break;
- default:
- if (current < 0)
- {
- current = materials.Pop() + magic.Dequeue();
- materials.Push(current);
- }
- else if (current == 0)
- {
- if (materials.Peek() == 0)
- {
- materials.Pop();
- }
- if(magic.Peek()==0)
- {
- magic.Dequeue();
- }
- }
- else
- {
- magic.Dequeue();
- int temp = materials.Pop() + 15;
- materials.Push(temp);
- }
- break;
- }
- }
- bool success = false;
- if (presents["Doll"] > 0 && presents["Wooden train"] > 0)
- {
- success = true;
- }
- else if (presents["Teddy bear"] > 0 && presents["Bicycle"] > 0)
- {
- success = true;
- }
- if (success)
- {
- Console.WriteLine("The presents are crafted! Merry Christmas!");
- }
- else
- {
- Console.WriteLine("No presents this Christmas!");
- }
- if (materials.Count > 0)
- {
- Console.WriteLine($"Materials left: {string.Join(", ", materials)}");
- }
- if (magic.Count > 0)
- {
- Console.WriteLine($"Magic left: {string.Join(", ", magic)}");
- }
- foreach (var present in presents.OrderBy(i => i.Key))
- {
- if (present.Value > 0)
- {
- Console.WriteLine($"{present.Key}: {present.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment