Advertisement
silvana1303

tank collector

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