Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main()
- {
- var gifts = Console.ReadLine().Split(" ").ToList();
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "No Money")
- {
- var splitedInput = input.Split(" ").ToList();
- if (splitedInput[0] == "OutOfStock")
- {
- if (splitedInput.Count() == 2)
- {
- for (int i = 0; i < gifts.Count; i++)
- {
- if (gifts[i].Contains(splitedInput[1]))
- {
- int index = gifts.IndexOf(splitedInput[1]);
- string outOfStockGift = splitedInput[1];
- gifts.Remove(splitedInput[1]);
- gifts.Insert(index, "None");
- }
- }
- }
- }
- else if (splitedInput[0] == "Required")
- {
- if (splitedInput.Count == 3)
- {
- string gift = splitedInput[1];
- int index = int.Parse(splitedInput[2]);
- if (index >= 0 && index < gifts.Count)
- {
- gifts.RemoveAt(index);
- gifts.Insert(index, gift);
- }
- }
- }
- else if (splitedInput[0] == "JustInCase")
- {
- if (splitedInput.Count() == 2)
- {
- int lastIndex = gifts.Count - 1;
- gifts.RemoveAt(lastIndex);
- gifts.Add(splitedInput[1]);
- }
- }
- }
- if (gifts.Contains("None"))
- {
- gifts.RemoveAll(gift => gift == "None");
- }
- Console.WriteLine(string.Join(" ", gifts));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement