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