Advertisement
Guest User

Tanks

a guest
Feb 27th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.82 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _3_Tanks_Collector
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> ownedTanks = Console.ReadLine().Split(", ").ToList();
  12.             int countOfCommands = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 1; i <= countOfCommands; i++)
  15.             {
  16.                 List<string> commands = Console.ReadLine().Split(", ").ToList();
  17.                 if (commands[0] == "Add")
  18.                 {
  19.                     if (!ownedTanks.Contains(commands[1]))
  20.                     {
  21.                         Console.WriteLine("Tank successfully bought");
  22.                         ownedTanks.Add(commands[1]);
  23.                     }
  24.                     else
  25.                     {
  26.                         Console.WriteLine("Tank is already bought");
  27.                     }
  28.                 }
  29.                 else if (commands[0] == "Remove")
  30.                 {
  31.                     if (ownedTanks.Contains(commands[1]))
  32.                     {
  33.                         Console.WriteLine("Tank successfully sold");
  34.                         ownedTanks.Remove(commands[1]);
  35.                     }
  36.                     else
  37.                     {
  38.                         Console.WriteLine("Tank not found");
  39.                     }
  40.                 }
  41.                 else if (commands[0] == "Remove At")
  42.                 {
  43.                     if (int.Parse(commands[1]) >= 0 && int.Parse(commands[1]) < ownedTanks.Count)
  44.                     {
  45.                         ownedTanks.RemoveAt(int.Parse(commands[1]));
  46.                         Console.WriteLine("Tank successfully sold");
  47.                     }
  48.                     else
  49.                     {
  50.                         Console.WriteLine("Index out of range");
  51.                         continue;
  52.                     }
  53.  
  54.                 }
  55.                 else if (commands[0] == "Insert")
  56.                 {
  57.                     if (int.Parse(commands[1]) >= 0 && int.Parse(commands[1]) < ownedTanks.Count)
  58.                     {
  59.                         if (!ownedTanks.Contains(commands[2]))
  60.                         {
  61.                             ownedTanks.Insert(int.Parse(commands[1]), commands[2]);
  62.                             Console.WriteLine("Tank successfully bought");
  63.                         }
  64.                         else
  65.                         {
  66.                             Console.WriteLine("Tank is already bought");
  67.                         }
  68.                     }
  69.                     else
  70.                     {
  71.                         Console.WriteLine("Index out of range");
  72.                         continue;
  73.                     }
  74.                 }
  75.             }
  76.             Console.WriteLine(string.Join(", ", ownedTanks));
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement