Lyubohd

03. Inventory

Jul 1st, 2020
1,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace Problem03
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> journal = Console.ReadLine().Split(", ").ToList();
  13.  
  14.             string input = Console.ReadLine(); // Drop - Wood
  15.             while ("Craft!" != input)
  16.             {
  17.                 string[] tokens = input.Split(" - ");
  18.                 string command = tokens[0];
  19.                 string item = tokens[1];
  20.  
  21.                 if ("Collect" == command)
  22.                 {
  23.                     if (!journal.Contains(item))
  24.                     {
  25.                         journal.Add(item);
  26.                     }
  27.                 }
  28.                 else if ("Drop" == command)
  29.                 {
  30.                     journal.Remove(item);
  31.                 }
  32.                 else if ("Combine Items" == command)
  33.                 {
  34.                     string[] items = item.Split(":");
  35.                     string oldItem = items[0];
  36.                     string newItem = items[1];
  37.  
  38.                     int index = journal.IndexOf(oldItem);
  39.                     if (index >= 0)
  40.                     {
  41.                         journal.Insert(index + 1, newItem);
  42.                     }
  43.                 }
  44.                 else if ("Renew" == command)
  45.                 {
  46.                     int index = journal.IndexOf(item);
  47.                     if (index >= 0)
  48.                     {
  49.                         string element = journal[index];
  50.                         journal.Remove(element);
  51.                         journal.Add(element);
  52.                     }
  53.                 }
  54.  
  55.                 input = Console.ReadLine();
  56.             }
  57.  
  58.             Console.WriteLine(string.Join(", ", journal));
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment