Advertisement
AlexMAlex

Untitled

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