Advertisement
yanass

Easter Gifts

Jun 28th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Easter_Gifts
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             string[] gifts = Console.ReadLine()
  12.                 .Split()
  13.                 .ToArray();
  14.  
  15.             while (true)
  16.             {
  17.                 string command = Console.ReadLine();
  18.                 if (command == "No Money")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 else
  24.                 {
  25.                     string[] checkGifts = command
  26.                         .Split()
  27.                         .ToArray();
  28.  
  29.                     string gift = checkGifts[1];
  30.  
  31.                     if (checkGifts[0] == "OutOfStock")
  32.                     {
  33.                         gifts = gifts.Select(x => x == gift ? "None" : x).ToArray();
  34.                     }
  35.  
  36.                     else if (checkGifts[0] == "Required")
  37.                     {
  38.                         int index = int.Parse(checkGifts[2]);
  39.  
  40.                         if (index >= 0 && index < gifts.Length)
  41.                         {
  42.                             gifts[index] = gift;
  43.                         }
  44.  
  45.                     }
  46.  
  47.                     else if (checkGifts[0] == "JustInCase")
  48.                     {
  49.                         gifts[gifts.Length - 1] = gift;
  50.                     }
  51.                 }
  52.             }
  53.  
  54.             foreach (var s in gifts.Where(s => s != "None"))
  55.             {
  56.                 Console.Write($"{s} ");
  57.             }
  58.  
  59.            
  60.  
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement