joro_thexfiles

Santa_Present_Factory

Feb 21st, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Santa_Present_Factory
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] data = Console.ReadLine()
  12.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.  
  16.             Stack<int> stack = new Stack<int>(data);
  17.  
  18.             data = Console.ReadLine()
  19.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  20.                 .Select(int.Parse)
  21.                 .ToArray();
  22.  
  23.             Queue<int> queue = new Queue<int>(data);
  24.  
  25.             Dictionary<string, int> dict = new Dictionary<string, int>();
  26.  
  27.             dict["Doll"] = 0;
  28.             dict["Wooden train"] = 0;
  29.             dict["Teddy bear"] = 0;
  30.             dict["Bicycle"] = 0;
  31.  
  32.             while (stack.Count > 0 && queue.Count > 0)
  33.             {
  34.                 int currentMaterial = stack.Peek();
  35.                 int currentMagic = queue.Peek();
  36.  
  37.                 if (currentMaterial == 0 || currentMagic == 0)
  38.                 {
  39.                     if (currentMaterial == 0)
  40.                     {
  41.                         stack.Pop();
  42.                     }
  43.  
  44.                     if (currentMagic == 0)
  45.                     {
  46.                         queue.Dequeue();
  47.                     }
  48.                     continue;
  49.                 }
  50.  
  51.                 int result = currentMaterial * currentMagic;
  52.  
  53.                 queue.Dequeue();
  54.                 stack.Pop();
  55.  
  56.                 if (result > 0)
  57.                 {
  58.                     if (result == 150)
  59.                     {
  60.                         dict["Doll"]++;
  61.                     }
  62.                     else if (result == 250)
  63.                     {
  64.                         dict["Wooden train"]++;
  65.                     }
  66.                     else if (result == 300)
  67.                     {
  68.                         dict["Teddy bear"]++;
  69.                     }
  70.                     else if (result == 400)
  71.                     {
  72.                         dict["Bicycle"]++;
  73.                     }
  74.                     else
  75.                     {
  76.                         stack.Push(currentMaterial + 15);
  77.                     }
  78.                 }
  79.                 else if (result < 0)
  80.                 {
  81.                     stack.Push(currentMaterial + currentMagic);
  82.                 }
  83.             }
  84.  
  85.             if ((dict["Doll"] >= 1 && dict["Wooden train"] >= 1) || (dict["Teddy bear"] >= 1 && dict["Bicycle"] >= 1))
  86.             {
  87.                 Console.WriteLine($"The presents are crafted! Merry Christmas!");
  88.             }
  89.             else
  90.             {
  91.                 Console.WriteLine($"No presents this Christmas!");
  92.             }
  93.  
  94.             if (stack.Count > 0)
  95.             {
  96.                 Console.WriteLine($"Materials left: {string.Join(", ", stack)}");
  97.             }
  98.  
  99.             if (queue.Count > 0)
  100.             {
  101.                 Console.WriteLine($"Magic left: {string.Join(", ", queue)}");
  102.             }
  103.  
  104.             dict
  105.                 .OrderBy(x => x.Key)
  106.                 .Where(x => x.Value > 0)
  107.                 .ToList()
  108.                 .ForEach(x => Console.WriteLine($"{x.Key}: {x.Value}"));
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment