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