Advertisement
alexbancheva

Invemtory_MidExam

Mar 2nd, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Inventory_MidExam
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> journal = Console.ReadLine()
  12.                 .Split(", ")
  13.                 .ToList();
  14.  
  15.             string command = Console.ReadLine();
  16.  
  17.             while (command != "Craft!")
  18.             {
  19.                 string[] newCommand = command.Split(" - ");
  20.                 //string instruction = newCommand[0];
  21.  
  22.                 if (newCommand[0] == "Collect")
  23.                 {
  24.                     string item = newCommand[1];
  25.  
  26.                     if (journal.Contains(item))
  27.                     {
  28.                         continue;
  29.                     }
  30.                     else
  31.                     {
  32.                         journal.Add(item);
  33.                     }
  34.                 }
  35.                 else if (newCommand[0] == "Drop")
  36.                 {
  37.                     string item = newCommand[1];
  38.  
  39.                     if (journal.Contains(item))
  40.                     {
  41.                         journal.Remove(item);
  42.                     }
  43.                 }
  44.                 else if (newCommand[0] == "Combine Items")
  45.                 {
  46.                     string items = newCommand[1];
  47.                     string[] newItems = items.Split(":");
  48.                     string itemOne = newItems[0];
  49.                     string itemTwo = newItems[1];
  50.  
  51.                     if (journal.Contains(itemOne))
  52.                     {
  53.                         int indexOldItem = journal.IndexOf(itemOne) + 1;
  54.                         journal.Insert(indexOldItem, itemTwo);
  55.                     }
  56.                 }
  57.                 else if (newCommand[0] == "Renew")
  58.                 {
  59.                     string item = newCommand[1];
  60.  
  61.                     if (journal.Contains(item))
  62.                     {
  63.                         journal.Remove(item);
  64.                         journal.Add(item);
  65.                     }
  66.                 }
  67.  
  68.                 command = Console.ReadLine();
  69.             }
  70.  
  71.             if (command == "Craft!")
  72.             {
  73.                 Console.WriteLine(string.Join(", ", journal));
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement