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