petarkobakov

Archery Tournament

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