using System; using System.Linq; using System.Collections.Generic; namespace apps { class Program { static void Main() { List Inventory = Get().Split(", ").ToList(); while (true) { string input = Get(); if (input == "Craft!") { break; } string[] inputs = input.Split(" - ").ToArray(); string command = inputs[0]; string target = inputs[1]; if (command == "Collect") { if (Inventory.Contains(target) == false) { Inventory.Add(target); } } if (command == "Drop") { Inventory.Remove(target); } if (command == "Renew") { Inventory.Remove(target); Inventory.Add(target); } if (command == "Combine Items") { string[] item = target.Split(':'); // check if old exists -> if then add the new after the old if (Inventory.Contains(item[0])) { Inventory.Remove(item[1]); int pos = FindListItemIndex(Inventory, item[0]); Inventory.Insert(pos + 1, item[1]); } } } Console.WriteLine(string.Join(", ", Inventory)); } static string Get() { return Console.ReadLine(); } static int FindListItemIndex(List collection, string target) { int position = 0; for (int i = 0; i < collection.Count; i++) { if (collection[i] == target) { position = i; break; } } return position; } } }