Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Weaponsmith_02._11._2019___G1
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> weaponStrings = Console.ReadLine().Split("|", StringSplitOptions.RemoveEmptyEntries).ToList();
  12.  
  13.             string command;
  14.  
  15.             while ((command = Console.ReadLine()) != "Done")
  16.             {
  17.                 string firstCommand = command.Split()[0];
  18.                 string secondCommand = command.Split()[1];
  19.  
  20.                 if (firstCommand == "Move")
  21.                 {
  22.                     int index = int.Parse(command.Split()[2]);
  23.  
  24.                     if (secondCommand == "Left")
  25.                     {
  26.                         if (index > 0 && index < weaponStrings.Count)
  27.                         {
  28.                             string temp = weaponStrings[index];
  29.                             weaponStrings[index] = weaponStrings[index - 1];
  30.                             weaponStrings[index - 1] = temp;
  31.  
  32.                             //weaponStrings.Insert(index - 1, weaponStrings[index]);
  33.                             //weaponStrings.RemoveAt(index + 1);
  34.                         }
  35.                     }
  36.                     else if (secondCommand == "Right")
  37.                     {
  38.                         if (index >= 0 && index < weaponStrings.Count - 1)
  39.                         {
  40.                             string temp = weaponStrings[index];
  41.                             weaponStrings[index] = weaponStrings[index + 1];
  42.                             weaponStrings[index + 1] = temp;
  43.  
  44.                             //weaponStrings.Insert(index + 2, weaponStrings[index]);
  45.                             //weaponStrings.RemoveAt(index);
  46.                         }
  47.                     }
  48.                 }
  49.                 else if (firstCommand == "Check")
  50.                 {
  51.                     if (secondCommand == "Even")
  52.                     {
  53.                         for (int i = 0; i < weaponStrings.Count; i++)
  54.                         {
  55.                             if (i % 2 == 0)
  56.                             {
  57.                                 Console.Write($"{weaponStrings[i]} ");
  58.                             }
  59.                         }
  60.                         Console.WriteLine();
  61.                     }
  62.                     else if (secondCommand == "Odd")
  63.                     {
  64.                         for (int i = 0; i < weaponStrings.Count; i++)
  65.                         {
  66.                             if (i % 2 != 0)
  67.                             {
  68.                                 Console.Write($"{weaponStrings[i]} ");
  69.                             }
  70.                         }
  71.                         Console.WriteLine();
  72.                     }
  73.                 }
  74.  
  75.  
  76.             }
  77.  
  78.             Console.WriteLine($"You crafted {string.Join("", weaponStrings)}!");
  79.  
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement