Advertisement
silvana1303

weaponsmith

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