Advertisement
DragomiraV

MoveRightMoveLeft

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