Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Numerics;
- using System.Text;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Reflection.Metadata.Ecma335;
- using System.Runtime.ExceptionServices;
- using System.Threading;
- using System.Text.RegularExpressions;
- namespace ConsoleApp24
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> products = Console.ReadLine().Split("|").ToList();
- string input = Console.ReadLine();
- while (input != "Shop!")
- {
- string[] commands = input.Split("%");
- switch (commands[0])
- {
- case "Important":
- if (products.Contains(commands[1]))
- {
- products.Remove(commands[1]);
- products.Insert(0, commands[1]);
- }
- else
- {
- products.Insert(0, commands[1]);
- }
- break;
- case "Add":
- if (!products.Contains(commands[1]))
- {
- products.Add(commands[1]);
- }
- else
- {
- Console.WriteLine("The product is already in the list");
- }
- break;
- case "Swap":
- if (!products.Contains(commands[1]))
- {
- Console.WriteLine($"Product {commands[1]} missing!");
- }
- else if (!products.Contains(commands[2]))
- {
- Console.WriteLine($"Product {commands[2]} missing!");
- }
- else
- {
- int index1 = products.IndexOf(commands[1]);
- int index2 = products.IndexOf(commands[2]);
- string temp = products[index1];
- products[index1] = products[index2];
- products[index2] = temp;
- }
- break;
- case "Remove":
- if (products.Contains(commands[1]))
- {
- products.Remove(commands[1]);
- }
- else
- {
- Console.WriteLine($"Product {commands[1]} isn't in the list.");
- }
- break;
- }
- input = Console.ReadLine();
- }
- for (int i = 0; i < products.Count; i++)
- {
- Console.WriteLine($"{i + 1}. {products[i]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment