Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Inventory
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> collection = Console.ReadLine()
  12. .Split(", ")
  13. .ToList();
  14.  
  15. string command = Console.ReadLine();
  16.  
  17. while (command != "Craft!")
  18. {
  19. string[] commandToArray = command.Split(" - ").ToArray();
  20.  
  21. if (commandToArray[0] == "Collect")
  22. {
  23. string item = commandToArray[1];
  24.  
  25. if (!collection.Contains(item))
  26. {
  27. collection.Add(item);
  28. }
  29. }
  30. if (commandToArray[0] == "Drop")
  31. {
  32. string item = commandToArray[1];
  33.  
  34. if (collection.Contains(item))
  35. {
  36. for (int i = 0; i < collection.Count; i++)
  37. {
  38. if (collection[i] == item)
  39. {
  40. collection.Remove(item);
  41. }
  42. }
  43. }
  44. }
  45. if (commandToArray[0] == "Combine Items")
  46. {
  47. string oldItem = commandToArray[1].Split(":")[0];
  48. string newItem = commandToArray[1].Split(":")[1];
  49.  
  50. if (collection.Contains(oldItem))
  51. {
  52. for (int i = 0; i < collection.Count; i++)
  53. {
  54. if (collection[i] == oldItem)
  55. {
  56. if (i < collection.Count - 1)
  57. {
  58. collection.Insert(i + 1, newItem);
  59. break;
  60. }
  61. else
  62. {
  63. collection.Add(newItem);
  64. }
  65. }
  66. }
  67. }
  68. }
  69. if (commandToArray[0] == "Renew")
  70. {
  71. string item = commandToArray[1];
  72.  
  73. if (collection.Contains(item))
  74. {
  75. for (int i = 0; i < collection.Count; i++)
  76. {
  77. if (collection[i] == item)
  78. {
  79. string temp = collection[i];
  80. collection[i] = collection[collection.Count - 1];
  81. collection[collection.Count - 1] = temp;
  82. }
  83. }
  84. }
  85. }
  86. command = Console.ReadLine();
  87. }
  88. Console.WriteLine(string.Join(", ", collection));
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement