Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Tanks_Collector
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> tanks = Console.ReadLine().Split(", ").ToList();
- int lines = int.Parse(Console.ReadLine());
- for (int i = 0; i < lines; i++)
- {
- string input = Console.ReadLine();
- string[] splittedInput = input.Split(", ");
- switch (splittedInput[0])
- {
- case "Add":
- if (tanks.Contains(splittedInput[1]))
- {
- Console.WriteLine("Tank is already bought");
- }
- else
- {
- Console.WriteLine("Tank successfully bought");
- tanks.Add(splittedInput[1]);
- }
- break;
- case "Remove":
- if (tanks.Contains(splittedInput[1]))
- {
- Console.WriteLine("Tank successfully sold");
- tanks.Remove(splittedInput[1]);
- }
- else
- {
- Console.WriteLine("Tank not found");
- }
- break;
- case "Remove At":
- if (int.Parse(splittedInput[1]) < tanks.Count && int.Parse(splittedInput[1]) >= 0)
- {
- Console.WriteLine("Tank successfully sold");
- tanks.RemoveAt(int.Parse(splittedInput[1]));
- }
- else
- {
- Console.WriteLine("Index out of range");
- }
- break;
- case "Insert":
- if (int.Parse(splittedInput[1]) < tanks.Count && int.Parse(splittedInput[1]) >= 0)
- {
- if (tanks.Contains(splittedInput[2]))
- {
- Console.WriteLine("Tank is already bought");
- }
- else
- {
- tanks.Insert(int.Parse(splittedInput[1]),splittedInput[2]);
- Console.WriteLine("Tank successfully bought");
- }
- }
- else
- {
- Console.WriteLine("Index out of range");
- }
- break;
- }
- }
- Console.WriteLine(string.Join(", ", tanks));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement