Advertisement
AnetaKoseva

SantasPresents

Jun 24th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Santa_sPresentFactory
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Stack<int> box = new Stack<int>( Console.ReadLine().Split().Select(int.Parse).ToArray());
  12.             Queue<int> magic = new Queue<int>(Console.ReadLine().Split().Select(int.Parse).ToArray());
  13.             Dictionary<string, Dictionary<int, int>> presents = new Dictionary<string, Dictionary<int, int>> {
  14.                  {"Doll", new Dictionary<int, int>{{ 150,0} } } ,
  15.                  {"Wooden train", new Dictionary<int, int>{ { 250,0} } },
  16.                 {"Teddy bear", new Dictionary<int, int>{ { 300,0} } },
  17.                  { "Bicycle", new Dictionary<int, int>{{ 400,0} } } ,
  18.             };
  19.             while(box.Count>0&& magic.Count>0)
  20.             {
  21.                 //box.Pop* //magic.Dequeue
  22.                 int currentBox = box.Peek();
  23.                 int currentMagic = magic.Peek();
  24.  
  25.                 if (currentBox==0)
  26.                 {
  27.                     box.Pop();
  28.                     continue;
  29.                 }
  30.                 if(currentMagic==0)
  31.                 {
  32.                     magic.Dequeue();
  33.                     continue;
  34.                 }
  35.                 int sum = currentBox * currentMagic;
  36.                 if (sum < 0)
  37.                 {
  38.                     box.Pop();
  39.                     magic.Dequeue();
  40.                     box.Push(sum);
  41.                     sum = 0;
  42.                 }
  43.                 sum = currentBox * currentMagic;
  44.                
  45.                 if ( sum>0)
  46.                 {
  47.                    
  48.                     foreach (var item in presents)
  49.                     {
  50.                         foreach (var toy in item.Value)
  51.                         {
  52.                             if (!item.Value.ContainsKey(sum))
  53.                             {
  54.                                 magic.Dequeue();
  55.                                 box.Push(currentBox + 15);
  56.                             }
  57.                             else
  58.                             {
  59.                                 magic.Dequeue();
  60.                                 box.Pop();
  61.                                 //увеличавам броя на подаръците
  62.                                
  63.                             }
  64.                         }
  65.                     }
  66.                    
  67.                 }
  68.                
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement