Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._School_Library
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int playerPoints = 0;
  10.  
  11. string targets = Console.ReadLine();
  12.  
  13. string[] targetsArray = targets.Split('|');
  14. int[] targetsArrayInt = new int[targetsArray.Length];
  15. for (int i = 0; i < targetsArray.Length; i++)
  16. {
  17. targetsArrayInt[i] = int.Parse(targetsArray[i]);
  18. }
  19.  
  20. string command = Console.ReadLine();
  21.  
  22. while (command != "Game over")
  23. {
  24. string[] commandArray = command.Split();
  25.  
  26. switch (commandArray[0])
  27. {
  28. case "Shoot":
  29. switch (commandArray[1][0])
  30. {
  31. case 'L':
  32. string[] commandLeft = commandArray[1].Split('@');
  33. int startIndexLeft = int.Parse(commandLeft[1]);
  34. int lengthLeft = int.Parse(commandLeft[2]);
  35.  
  36. if (startIndexLeft >= 0 && startIndexLeft < targetsArrayInt.Length)
  37. {
  38. for (int i = 0; i < lengthLeft; i++)
  39. {
  40. startIndexLeft--;
  41. if (startIndexLeft == -1)
  42. {
  43. startIndexLeft = targetsArrayInt.Length - 1;
  44. }
  45. }
  46. if (targetsArrayInt[startIndexLeft] - 5 >= 5)
  47. {
  48. targetsArrayInt[startIndexLeft] -= 5;
  49. playerPoints += 5;
  50. }
  51. else if (targetsArrayInt[startIndexLeft] - 5 < 5)
  52. {
  53. playerPoints += targetsArrayInt[startIndexLeft];
  54. targetsArrayInt[startIndexLeft] = 0;
  55. }
  56. }
  57. break;
  58. case 'R':
  59. string[] commandRight = commandArray[1].Split('@');
  60. int startIndexRight = int.Parse(commandRight[1]);
  61. int lengthRight = int.Parse(commandRight[2]);
  62.  
  63. if (startIndexRight >= 0 && startIndexRight < targetsArrayInt.Length)
  64. {
  65. for (int j = 0; j < lengthRight; j++)
  66. {
  67. startIndexRight++;
  68. if (startIndexRight == targetsArrayInt.Length)
  69. {
  70. startIndexRight = 0;
  71. }
  72. }
  73. if (targetsArrayInt[startIndexRight] - 5 >= 5)
  74. {
  75. targetsArrayInt[startIndexRight] -= 5;
  76. playerPoints += 5;
  77. }
  78. else if (targetsArrayInt[startIndexRight] - 5 < 5)
  79. {
  80. playerPoints += targetsArrayInt[startIndexRight];
  81. targetsArrayInt[startIndexRight] = 0;
  82. }
  83. }
  84. break;
  85. }
  86. break;
  87. case "Reverse":
  88. int[] temp = new int[targetsArrayInt.Length];
  89. int num = 0;
  90. for (int i = targetsArrayInt.Length - 1; i >= 0; i--)
  91. {
  92. temp[num] = targetsArrayInt[i];
  93. num++;
  94. }
  95. targetsArrayInt = temp;
  96. break;
  97. }
  98.  
  99. command = Console.ReadLine();
  100. }
  101.  
  102. Console.WriteLine(string.Join(" - ", targetsArrayInt));
  103. Console.WriteLine($"Iskren finished the archery tournament with {playerPoints} points!");
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement