Daniel_007

01. Santa's Present Factory

Jun 27th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CSh_Advanced_Retake_Exam___17_December_2019
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] materialsValues = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int[] magicValues = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.             Stack<int> materials = new Stack<int>();
  14.             Queue<int> magic = new Queue<int>();
  15.             Dictionary<string, int> presents = new Dictionary<string, int>();
  16.             presents["Doll"] = 0;
  17.             presents["Wooden train"] = 0;
  18.             presents["Teddy bear"] = 0;
  19.             presents["Bicycle"] = 0;
  20.             foreach (var number in materialsValues)
  21.             {
  22.                 materials.Push(number);
  23.             }
  24.             foreach (var number in magicValues)
  25.             {
  26.                 magic.Enqueue(number);
  27.             }
  28.             while (true)
  29.             {
  30.                 if (materials.Count <= 0 || magic.Count <= 0)
  31.                 {
  32.                     break;
  33.                 }
  34.                 int current = materials.Peek() * magic.Peek();
  35.                 switch (current)
  36.                 {
  37.                     case 150:
  38.                         materials.Pop();
  39.                         magic.Dequeue();
  40.                         presents["Doll"]++;
  41.  
  42.                         break;
  43.                     case 250:
  44.                         materials.Pop();
  45.                         magic.Dequeue();
  46.                         presents["Wooden train"]++;
  47.                         break;
  48.                     case 300:
  49.                         materials.Pop();
  50.                         magic.Dequeue();
  51.                         presents["Teddy bear"]++;
  52.                         break;
  53.                     case 400:
  54.                         materials.Pop();
  55.                         magic.Dequeue();
  56.                         presents["Bicycle"]++;
  57.                         break;
  58.                     default:
  59.                         if (current < 0)
  60.                         {
  61.                             current = materials.Pop() + magic.Dequeue();
  62.                             materials.Push(current);
  63.                         }
  64.                         else if (current == 0)
  65.                         {
  66.                             if (materials.Peek() == 0)
  67.                             {
  68.                                 materials.Pop();
  69.                             }
  70.                             if(magic.Peek()==0)
  71.                             {
  72.                                 magic.Dequeue();
  73.                             }
  74.                            
  75.                         }
  76.                         else
  77.                         {
  78.                             magic.Dequeue();
  79.                             int temp = materials.Pop() + 15;
  80.                             materials.Push(temp);
  81.                         }
  82.                         break;
  83.                 }
  84.             }
  85.  
  86.             bool success = false;
  87.             if (presents["Doll"] > 0 && presents["Wooden train"] > 0)
  88.             {
  89.                 success = true;
  90.             }
  91.             else if (presents["Teddy bear"] > 0 && presents["Bicycle"] > 0)
  92.             {
  93.                 success = true;
  94.             }
  95.  
  96.             if (success)
  97.             {
  98.                 Console.WriteLine("The presents are crafted! Merry Christmas!");
  99.             }
  100.             else
  101.             {
  102.                 Console.WriteLine("No presents this Christmas!");
  103.             }
  104.  
  105.             if (materials.Count > 0)
  106.             {
  107.                 Console.WriteLine($"Materials left: {string.Join(", ", materials)}");
  108.             }
  109.             if (magic.Count > 0)
  110.             {
  111.                 Console.WriteLine($"Magic left: {string.Join(", ", magic)}");
  112.             }
  113.  
  114.             foreach (var present in presents.OrderBy(i => i.Key))
  115.             {
  116.                 if (present.Value > 0)
  117.                 {
  118.                     Console.WriteLine($"{present.Key}: {present.Value}");
  119.                 }
  120.             }
  121.         }
  122.     }
Advertisement
Add Comment
Please, Sign In to add comment