Stan0033

Untitled

Jul 5th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace apps
  6. {
  7. class Program
  8. {
  9.  
  10. static void Main()
  11. {
  12. List<string> Inventory = Get().Split(", ").ToList();
  13. while (true)
  14. {
  15. string input = Get(); if (input == "Craft!") { break; }
  16. string[] inputs = input.Split(" - ").ToArray();
  17. string command = inputs[0];
  18. string target = inputs[1];
  19. if (command == "Collect") { if (Inventory.Contains(target) == false) { Inventory.Add(target); } }
  20. if (command == "Drop") { Inventory.Remove(target); }
  21. if (command == "Renew") { Inventory.Remove(target); Inventory.Add(target); }
  22. if (command == "Combine Items")
  23. {
  24. string[] item = target.Split(':'); // check if old exists -> if then add the new after the old
  25. if (Inventory.Contains(item[0]))
  26. {
  27. Inventory.Remove(item[1]);
  28. int pos = FindListItemIndex(Inventory, item[0]);
  29. Inventory.Insert(pos + 1, item[1]);
  30.  
  31. }
  32. }
  33. }
  34. Console.WriteLine(string.Join(", ", Inventory));
  35. }
  36.  
  37. static string Get() { return Console.ReadLine(); }
  38. static int FindListItemIndex(List<string> collection, string target)
  39. {
  40. int position = 0;
  41.  
  42. for (int i = 0; i < collection.Count; i++)
  43. {
  44. if (collection[i] == target) { position = i; break; }
  45. }
  46. return position;
  47. }
  48.  
  49.  
  50.  
  51. }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment