Advertisement
Vasilena_Vasileva

Untitled

Feb 26th, 2020
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem_3._Tanks_Collector
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> tanksOwned = Console.ReadLine().Split(", ").ToList();
  12. int commandsNumber = int.Parse(Console.ReadLine());
  13.  
  14.  
  15. for (int i = 0; i < commandsNumber; i++)
  16. {
  17. string line = Console.ReadLine();
  18. string[] tokens = line.Split(", ");
  19. string command = tokens[0];
  20.  
  21. if (command == "Add")
  22. {
  23. string tankName = tokens[1];
  24. if (tanksOwned.Contains(tankName))
  25. {
  26. Console.WriteLine("Tank is already bought");
  27. }
  28. else
  29. {
  30. Console.WriteLine("Tank successfully bought");
  31. tanksOwned.Add(tankName);
  32. }
  33.  
  34. }
  35. else if (command == "Remove")
  36. {
  37. string name = tokens[1];
  38. if (tanksOwned.Contains(name))
  39. {
  40. Console.WriteLine("Tank successfully sold");
  41. tanksOwned.Remove(name);
  42. }
  43. else
  44. {
  45. Console.WriteLine("Tank not found");
  46. }
  47. }
  48. else if (command == "Remove At")
  49. {
  50. int index = int.Parse(tokens[1]);
  51. if (index >= 0 && index < tanksOwned.Count)
  52. {
  53. tanksOwned.RemoveAt(index);
  54. Console.WriteLine("Tank successfully sold");
  55. }
  56. else
  57. {
  58. Console.WriteLine("Index out of range");
  59. }
  60. }
  61. else if (command == "Insert")
  62. {
  63. int index = int.Parse(tokens[1]);
  64. string tankName = tokens[2];
  65. if (index >= 0 && index < tanksOwned.Count)
  66. {
  67. if (tanksOwned.Contains(tankName))
  68. {
  69. Console.WriteLine("Tank is already bought");
  70. }
  71. else
  72. {
  73. tanksOwned.Insert(index, tankName);
  74. Console.WriteLine("Tank successfully bought");
  75. }
  76. }
  77. else
  78. {
  79. Console.WriteLine("Index out of range");
  80. }
  81. }
  82. }
  83. Console.WriteLine(string.Join(", ", tanksOwned));
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement