Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Read The Input
- List<string> inventory = Console.ReadLine()
- .Split(", ", StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Craft!")
- {
- break;
- }
- string[] command = line
- .Split(" - ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string firstCommand = command[0];
- switch (firstCommand)
- {
- case "Collect":
- if (!inventory.Contains(command[1]))
- {
- inventory.Add(command[1]);
- }
- break;
- case "Drop":
- if (inventory.Contains(command[1]))
- {
- inventory.Remove(command[1]);
- }
- break;
- case "Combine Items":
- string oldItem = string.Empty;
- string newItem = string.Empty;
- for (int i = 1; i < command.Length; i++)
- {
- string[] combineItem = command[i]
- .Split(":", StringSplitOptions.RemoveEmptyEntries);
- oldItem = combineItem[0];
- newItem = combineItem[1];
- }
- if (inventory.Contains(oldItem))
- {
- for (int i = 0; i < inventory.Count; i++)
- {
- if (inventory[i] == oldItem)
- {
- int index = i + 1;
- if (index > 0)
- {
- inventory.Insert(index, newItem);
- }
- break;
- }
- }
- }
- break;
- case "Renew":
- if (inventory.Contains(command[1]))
- {
- string firstElement = inventory[0];
- inventory.Add(command[1]);
- inventory.Remove(firstElement);
- }
- break;
- }
- }
- Console.WriteLine(string.Join(", ", inventory));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement