Advertisement
dragonbs

CoffeeLover

Feb 19th, 2023 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System.Data;
  2. using System.Security.Cryptography.X509Certificates;
  3.  
  4. List<string> coffees = Console.ReadLine()
  5.     .Split()
  6.     .ToList();
  7.  
  8. int n = int.Parse(Console.ReadLine());
  9.  
  10. for (int i = 0; i < n; i++)
  11. {
  12.     string[] command = Console.ReadLine()
  13.         .Split();
  14.  
  15.     if (command[0] == "Include")
  16.     {
  17.         string coffee = command[1];
  18.         coffees.Add(coffee);
  19.     }
  20.     else if (command[0] == "Remove")
  21.     {
  22.         string commandInfo = command[1];
  23.         int numbersCoffeeToRemove = int.Parse(command[2]);
  24.  
  25.         if (numbersCoffeeToRemove <= coffees.Count)
  26.         {
  27.             if (commandInfo == "first")
  28.             {
  29.                 coffees.RemoveRange(0, numbersCoffeeToRemove);
  30.             }
  31.             else
  32.             {
  33.                 coffees.RemoveRange(coffees.Count - numbersCoffeeToRemove, numbersCoffeeToRemove);
  34.             }
  35.         }
  36.     }
  37.     else if (command[0] == "Prefer")
  38.     {
  39.         int index1 = int.Parse(command[1]);
  40.         int index2 = int.Parse(command[2]);
  41.  
  42.         if (index1 >= 0 && index1 <= coffees.Count && index2 >= 0 && index2 <= coffees.Count)
  43.         {
  44.             string corectElement = coffees[index1];
  45.             coffees[index1] = coffees[index2];
  46.             coffees[index2] = corectElement;
  47.         }
  48.     }
  49.     else if (command[0] == "Reverse")
  50.     {
  51.         coffees.Reverse();
  52.  
  53.     }
  54. }
  55.  
  56. Console.WriteLine("Coffees:");
  57. Console.WriteLine(string.Join(" ", coffees));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement