Advertisement
knoteva

Untitled

Sep 30th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace Black_Flag
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var input = Console.ReadLine()
  12.               .Split('|').Where(s => !string.IsNullOrWhiteSpace(s))
  13.               .ToList();
  14.  
  15.             string commandLine;
  16.  
  17.             while ((commandLine = Console.ReadLine()) != "Done")
  18.             {
  19.                 if (commandLine.Split(" ")[0] == "Move")
  20.                 {
  21.                     var splitCommands = commandLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  22.                     string command = splitCommands[1];
  23.                     int index = int.Parse(splitCommands[2]);
  24.  
  25.                     if (command == "Left")
  26.                     {
  27.                         if (index - 1 >= 0)
  28.                         {
  29.                             var value = input[index];
  30.                             input.RemoveAt(index);
  31.                             input.Insert(index - 1, value);
  32.                         }
  33.                     }
  34.                     else
  35.                     {
  36.                         if (index + 1 < input.Count)
  37.                         {
  38.                             var value = input[index];
  39.                             input.RemoveAt(index);
  40.                             input.Insert(index + 1, value);
  41.                         }
  42.                     }
  43.                 }
  44.                 else
  45.                 {
  46.                     int index = int.Parse(commandLine.Split(" ")[1]);
  47.                     if (index >= 0 && index < input.Count)
  48.                     {
  49.                         input.RemoveAt(index);
  50.                     }
  51.                 }
  52.             }
  53.             Console.WriteLine($"You crafted {string.Join("", input)}!");
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement