Advertisement
AngelVasilev

SoftUni Fundamentals - Tanks Collector

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