Advertisement
AnastasiyaG

Untitled

Feb 27th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Weaponsmith
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. List<string> weaponsName = Console.ReadLine()
  13. .Split("|", StringSplitOptions.RemoveEmptyEntries)
  14. .ToList();
  15. StringBuilder weapon = new StringBuilder();
  16.  
  17. while (true)
  18. {
  19. string[] command = Console.ReadLine().Split().ToArray();
  20. if (command[0] == "Done")
  21. { break; }
  22.  
  23. switch (command[0])
  24. {
  25. case "Move":
  26. if (command[1] == "Left")
  27. {
  28. int index = int.Parse(command[2]); if (index <= 0 || index > weaponsName.Count - 1)
  29. { continue; }
  30. int a = -1;
  31. GetMovedList(weaponsName, index,a);
  32. }
  33. if (command[1] == "Right")
  34. {
  35. int index = int.Parse(command[2]); if (index < 0 || index >= weaponsName.Count - 1)
  36. { continue; }
  37. int a = +1;
  38. GetMovedList(weaponsName, index, a);
  39. }
  40.  
  41. break;
  42.  
  43. case "Check":
  44. if (command[1] == "Even")
  45. { int b = 0;
  46.  
  47. GetPrintChecked(weaponsName, b);
  48.  
  49. }
  50. if (command[1] == "Odd")
  51. {
  52. int b = 1;
  53.  
  54. GetPrintChecked(weaponsName, b);
  55.  
  56. }
  57. break;
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
  66. foreach (var letters in weaponsName)
  67. {
  68. weapon.Append(letters);
  69.  
  70. }
  71. Console.WriteLine($"You crafted {weapon}!");
  72. }
  73.  
  74.  
  75. static void GetPrintChecked(List<string> list, int b)
  76. {
  77. for (int i = 0; i < list.Count; i++)
  78. {
  79. if (i % 2 == b)
  80. Console.Write(list[i] +" ");
  81.  
  82. }
  83.  
  84. Console.WriteLine();
  85. }
  86.  
  87. static List<string> GetMovedList(List<string> weaponsName, int index, int a)
  88. {
  89. if (index <= weaponsName.Count - 1 && index >= 0)
  90. { string forMove = weaponsName[index];
  91.  
  92. string second = weaponsName[index +a];
  93. weaponsName.RemoveAt(index);
  94. weaponsName.Insert(index, second);
  95. weaponsName.RemoveAt(index +a);
  96. weaponsName.Insert(index +a, forMove);
  97.  
  98. }
  99. return weaponsName;
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement