Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02._Easter_Gifts
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> giftList = Console.ReadLine().Split().ToList();
- while (true)
- {
- string[] theCommand = Console.ReadLine().Split();
- if (theCommand[0] == "No")
- {
- break;
- }
- else if (theCommand[0] == "OutOfStock")
- {
- // OutOfStock {gift}
- // Find the gifts with this name in your collection,
- // if there are any, and change their values to "None".
- while (true)
- {
- int index = giftList.IndexOf(theCommand[1]);
- if (index < 0)
- {
- break;
- }
- else
- {
- giftList[index] = "None";
- }
- }
- }
- else if (theCommand[0] == "Required")
- {
- // Required {gift} {index}
- // Replace the value of the current gift on the given index with this gift,
- // if the index is valid.
- int index = int.Parse(theCommand[2]);
- if (index >= 0 && index < giftList.Count)
- {
- giftList[index] = theCommand[1];
- }
- }
- else if (theCommand[0] == "JustInCase")
- {
- // JustInCase {gift}
- // Replace the value of your last gift with this one
- int lastIndex = giftList.Count - 1;
- giftList.RemoveAt(lastIndex);
- giftList.Add(theCommand[1]);
- }
- }
- foreach (string item in giftList)
- {
- if (item != "None")
- {
- Console.Write(item + " ");
- }
- }
- //Console.WriteLine("Hello World!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment