Teo_Yanchev

C# Fundamentals - 02. ArcheryTournament - MidExam 10.12.2019

Oct 20th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace aa
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] archeryField = Console.ReadLine()
  11. .Split('|')
  12. .Select(int.Parse)
  13. .ToArray();
  14.  
  15. int pointsIskren = 0;
  16. string command = Console.ReadLine();
  17. while (command != "Game over")
  18. {
  19. string[] currentCommand = command.Split('@');
  20. string instruction = currentCommand[0];
  21.  
  22. if (instruction == "Shoot Left")
  23. {
  24. int index = int.Parse(currentCommand[1]);
  25. int length = int.Parse(currentCommand[2]);
  26.  
  27. if (0 <= index && index <= archeryField.Length - 1)
  28. {
  29. while (length != 0)
  30. {
  31. if (index > 0)
  32. {
  33. index -= 1;
  34. length -= 1;
  35. }
  36.  
  37. else if (index == 0)
  38. {
  39. index = archeryField.Length - 1;
  40. length -= 1;
  41. }
  42. }
  43. }
  44.  
  45. else
  46. {
  47. command = Console.ReadLine();
  48. continue;
  49. }
  50.  
  51. if (archeryField[index] >= 5)
  52. {
  53. pointsIskren += 5;
  54. archeryField[index] -= 5;
  55. }
  56.  
  57. else
  58. {
  59. pointsIskren += archeryField[index];
  60. archeryField[index] = 0;
  61. }
  62. }
  63.  
  64. else if (instruction == "Shoot Right")
  65. {
  66. int index = int.Parse(currentCommand[1]);
  67. int length = int.Parse(currentCommand[2]);
  68.  
  69. if (0 <= index && index <= archeryField.Length - 1)
  70. {
  71. while (length != 0)
  72. {
  73. if (index < archeryField.Length - 1)
  74. {
  75. index += 1;
  76. length -= 1;
  77. }
  78.  
  79. else if (index == archeryField.Length - 1)
  80. {
  81. index = 0;
  82. length -= 1;
  83. }
  84. }
  85. }
  86.  
  87. else
  88. {
  89. command = Console.ReadLine();
  90. continue;
  91. }
  92.  
  93. if (archeryField[index] >= 5)
  94. {
  95. pointsIskren += 5;
  96. archeryField[index] -= 5;
  97. }
  98.  
  99. else
  100. {
  101. pointsIskren += archeryField[index];
  102. archeryField[index] = 0;
  103. }
  104. }
  105.  
  106. else if (instruction == "Reverse")
  107. {
  108. Array.Reverse(archeryField);
  109. }
  110.  
  111. command = Console.ReadLine();
  112. }
  113.  
  114. Console.WriteLine(string.Join(" - ", archeryField));
  115. Console.WriteLine($"Iskren finished the archery tournament with {pointsIskren} points!");
  116. }
  117. }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment