Advertisement
Guest User

Untitled

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