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 numComand = int.Parse(Console.ReadLine());
- for (int i = 0; i < numComand; i++)
- {
- string[] input = Console.ReadLine().Split(", ").ToArray();
- string comand = input[0];
- string currTank = input[1];
- switch (comand)
- {
- case "Add":
- {
- bool haveTank = tanks.Contains(currTank);
- if (haveTank)
- {
- Console.WriteLine("Tank is already bought");
- }
- else
- {
- tanks.Add(currTank);
- Console.WriteLine("Tank successfully bought");
- }
- break;
- }
- case "Remove":
- {
- bool haveTank = tanks.Contains(currTank);
- if (haveTank)
- {
- tanks.Remove(currTank);
- Console.WriteLine("Tank successfully sold");
- }
- else
- {
- Console.WriteLine("Tank not found");
- }
- break;
- }
- case "Remove At":
- {
- int currIndex = int.Parse(currTank);
- if (currIndex >= 0 && currIndex < tanks.Count)
- {
- tanks.RemoveAt(currIndex);
- Console.WriteLine("Tank successfully sold");
- }
- else
- {
- Console.WriteLine("Index out of range");
- }
- break;
- }
- case "Insert":
- {
- int index = int.Parse(currTank);
- string newTank = input[2];
- bool haveTank = tanks.Contains(currTank);
- if (index < 0 || index > tanks.Count)
- {
- Console.WriteLine("Index out of range");
- break;
- }
- if (haveTank)
- {
- Console.WriteLine("Tank is already bought");
- }
- else
- {
- tanks.Insert(index, newTank);
- Console.WriteLine("Tank successfully bought");
- }
- break;
- }
- }
- }
- Console.WriteLine(string.Join(", ", tanks));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement