Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace fundamental14
- {
- class MainClass
- {
- public static void Main()
- {
- List<string> tank = Console.ReadLine().Split(", ").ToList();
- int number = int.Parse(Console.ReadLine());
- for (int i = 0; i < number; i++)
- {
- string[] array = Console.ReadLine().Split($", ").ToArray();
- string command = array[0];
- int index = 0;
- string tankName = string.Empty;
- if (command == "Add")
- {
- string newTank = array[1];
- if (tank.Contains(newTank))
- {
- Console.WriteLine("Tank is already bought");
- }
- else
- {
- tank.Add(newTank);
- Console.WriteLine("Tank successfully bought");
- }
- }
- else if (command == "Remove")
- {
- tankName = array[1];
- if(tank.Contains(tankName))
- {
- Console.WriteLine("Tank successfully sold");
- tank.Remove(tankName);
- }
- else
- {
- Console.WriteLine("Tank not found");
- }
- }
- else if (command == "Remove At")
- {
- index = int.Parse(array[1]);
- if (index >= 0 && index < tank.Count)
- {
- Console.WriteLine("Tank successfully sold");
- tank.RemoveAt(index);
- }
- else
- {
- Console.WriteLine("Index out of range");
- }
- }
- else if (command == "Insert")
- {
- index = int.Parse(array[1]);
- tankName = array[2];
- if (index >= 0 && index < tank.Count)
- {
- if (tank.Contains(tankName))
- {
- Console.WriteLine("Tank is already bought");
- }
- else
- {
- Console.WriteLine("Tank successfully bought");
- tank.Insert(index, tankName);
- }
- }
- else
- {
- Console.WriteLine("Index out of range");
- }
- }
- }
- Console.WriteLine(string.Join(", ", tank));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement