aggressiveviking

Untitled

Jun 22nd, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Easter_Gifts
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> giftList = Console.ReadLine().Split().ToList();
  12.  
  13.             while (true)
  14.             {
  15.                 string[] theCommand = Console.ReadLine().Split();
  16.  
  17.                 if (theCommand[0] == "No")
  18.                 {
  19.                     break;
  20.                 }
  21.                 else if (theCommand[0] == "OutOfStock")
  22.                 {
  23.                     // OutOfStock {gift}
  24.                     // Find the gifts with this name in your collection,
  25.                     // if there are any, and change their values to "None".
  26.                     while (true)
  27.                     {
  28.                         int index = giftList.IndexOf(theCommand[1]);
  29.  
  30.                         if (index < 0)
  31.                         {
  32.                             break;
  33.                         }
  34.                         else
  35.                         {
  36.                             giftList[index] = "None";
  37.                         }
  38.                     }
  39.                 }
  40.                 else if (theCommand[0] == "Required")
  41.                 {
  42.                     // Required {gift} {index}
  43.                     // Replace the value of the current gift on the given index with this gift,
  44.                     // if the index is valid.
  45.                     int index = int.Parse(theCommand[2]);
  46.  
  47.                     if (index >= 0 && index < giftList.Count)
  48.                     {
  49.                         giftList[index] = theCommand[1];
  50.                     }
  51.                 }
  52.                 else if (theCommand[0] == "JustInCase")
  53.                 {
  54.                     // JustInCase {gift}
  55.                     // Replace the value of your last gift with this one
  56.                     int lastIndex = giftList.Count - 1;
  57.  
  58.                     giftList.RemoveAt(lastIndex);
  59.  
  60.                     giftList.Add(theCommand[1]);
  61.                 }
  62.             }
  63.  
  64.             foreach (string item in giftList)
  65.             {
  66.                 if (item != "None")
  67.                 {
  68.                     Console.Write(item + " ");
  69.                 }
  70.             }
  71.  
  72.             //Console.WriteLine("Hello World!");
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment