joro_thexfiles

Santa_Present_Factory

Feb 20th, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 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.                 if (result > 0)
  54.                 {
  55.                     if (result == 150)
  56.                     {
  57.                         dict["Doll"]++;
  58.                     }
  59.                     else if (result == 200)
  60.                     {
  61.                         dict["Wooden train"]++;
  62.                     }
  63.                     else if (result == 300)
  64.                     {
  65.                         dict["Teddy bear"]++;
  66.                     }
  67.                     else if (result == 400)
  68.                     {
  69.                         dict["Bicycle"]++;
  70.                     }
  71.                     else
  72.                     {
  73.                         stack.Push(stack.Pop() + 15);
  74.                         queue.Dequeue();
  75.                         continue;
  76.                     }
  77.                 }
  78.                 else if (result < 0)
  79.                 {
  80.                     stack.Push(stack.Pop() + queue.Dequeue());
  81.                     continue;
  82.                 }
  83.  
  84.                 stack.Pop();
  85.                 queue.Dequeue();
  86.             }
  87.  
  88.             if ((dict["Doll"] >= 1 && dict["Wooden train"] >= 1) || (dict["Teddy bear"] >= 1 && dict["Bicycle"] >= 1))
  89.             {
  90.                 Console.WriteLine($"The presents are crafted! Merry Christmas!");
  91.             }
  92.             else
  93.             {
  94.                 Console.WriteLine($"No presents this Christmas!");
  95.             }
  96.  
  97.             if (stack.Count > 0)
  98.             {
  99.                 Console.WriteLine($"Materials left: {string.Join(", ", stack)}");
  100.             }
  101.  
  102.             if (queue.Count > 0)
  103.             {
  104.                 Console.WriteLine($"Magic left: {string.Join(", ", queue)}");
  105.             }
  106.  
  107.             dict
  108.                 .Where(x => x.Value > 0)
  109.                 .OrderBy(x => x.Key)
  110.                 .ToList()
  111.                 .ForEach(x => Console.WriteLine($"{x.Key}: {x.Value}"));
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment