Advertisement
nikolayneykov

Untitled

Apr 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         string[] namesOfGifts = Console.ReadLine().Split(" ");
  9.  
  10.         string input = string.Empty;
  11.  
  12.         while ((input = Console.ReadLine()) != "No Money")
  13.         {
  14.             string[] tokens = input.Split(" ");
  15.             string command = tokens[0];
  16.  
  17.             if (command == "OutOfStock")
  18.             {
  19.                 string gift = tokens[1];
  20.                 int index = Array.IndexOf(namesOfGifts, gift);
  21.  
  22.                 while (index != -1)
  23.                 {
  24.                     namesOfGifts[index] = "None";
  25.                     index = Array.IndexOf(namesOfGifts, gift);
  26.                 }
  27.             }
  28.             else if (command == "Required")
  29.             {
  30.                 string gift = tokens[1];
  31.                 int index = int.Parse(tokens[2]);
  32.  
  33.                 if (index >= 0 && index < namesOfGifts.Length)
  34.                 {
  35.                     namesOfGifts[index] = gift;
  36.                 }
  37.             }
  38.             else if (command == "JustInCase")
  39.             {
  40.                 string gift = tokens[1];
  41.  
  42.                 namesOfGifts[namesOfGifts.Length - 1] = gift;
  43.             }
  44.         }
  45.  
  46.         namesOfGifts = namesOfGifts.Where(x => x != "None").ToArray();
  47.  
  48.         Console.WriteLine(string.Join(" ", namesOfGifts));
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement