Advertisement
VickSuna

Untitled

Jun 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _20191102_Group_1_2._Weaponsmith
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> weaponName = Console.ReadLine()
  12. .Split('|', StringSplitOptions.RemoveEmptyEntries)
  13. .ToList();
  14.  
  15. while (true)
  16. {
  17. string[] command = Console.ReadLine().Split();
  18.  
  19. if (command[0] == "Done")
  20. {
  21. break;
  22. }
  23. else if (command[1] == "Left")
  24. {
  25. int index = int.Parse(command[2]);
  26.  
  27. if (index > 0 && index < weaponName.Count) // само > за да не стане отрицателен индекса;
  28. {
  29. string temp = weaponName[index - 1];
  30. weaponName[index - 1] = weaponName[index];
  31. weaponName[index] = temp;
  32. }
  33.  
  34. }
  35. else if (command[1] == "Right")
  36. {
  37. int index = int.Parse(command[2]);
  38.  
  39. if (index >= 0 && index < weaponName.Count - 1) // аналогично
  40. {
  41. string temp = weaponName[index + 1];
  42. weaponName[index + 1] = weaponName[index];
  43. weaponName[index] = temp;
  44. }
  45.  
  46. }
  47. else if (command[1] == "Even")
  48. {
  49. List<string> even = new List<string>();
  50.  
  51. for (int i = 0; i < weaponName.Count - 1; i++)
  52. {
  53. string currentString = weaponName[i];
  54.  
  55. if (i % 2 == 0)
  56. {
  57. even.Add(currentString);
  58. }
  59. }
  60.  
  61. Console.WriteLine(String.Join(" ", even));
  62. }
  63. else if (command[1] == "Odd")
  64. {
  65. List<string> odd = new List<string>();
  66.  
  67. for (int i = 0; i < weaponName.Count - 1; i++)
  68. {
  69. string currentString = weaponName[i];
  70.  
  71. if (i % 2 != 0)
  72. {
  73. odd.Add(currentString);
  74. }
  75. }
  76.  
  77. Console.WriteLine(String.Join(" ", odd));
  78. }
  79.  
  80. }
  81.  
  82. Console.WriteLine("You crafted " + String.Join("", weaponName) + "!");
  83.  
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement