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