Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _03._School_Library
- {
- class Program
- {
- static void Main(string[] args)
- {
- int playerPoints = 0;
- string targets = Console.ReadLine();
- string[] targetsArray = targets.Split('|');
- int[] targetsArrayInt = new int[targetsArray.Length];
- for (int i = 0; i < targetsArray.Length; i++)
- {
- targetsArrayInt[i] = int.Parse(targetsArray[i]);
- }
- string command = Console.ReadLine();
- while (command != "Game over")
- {
- string[] commandArray = command.Split();
- switch (commandArray[0])
- {
- case "Shoot":
- switch (commandArray[1][0])
- {
- case 'L':
- string[] commandLeft = commandArray[1].Split('@');
- int startIndexLeft = int.Parse(commandLeft[1]);
- int lengthLeft = int.Parse(commandLeft[2]);
- if (startIndexLeft >= 0 && startIndexLeft < targetsArrayInt.Length)
- {
- for (int i = 0; i < lengthLeft; i++)
- {
- startIndexLeft--;
- if (startIndexLeft == -1)
- {
- startIndexLeft = targetsArrayInt.Length - 1;
- }
- }
- if (targetsArrayInt[startIndexLeft] - 5 >= 5)
- {
- targetsArrayInt[startIndexLeft] -= 5;
- playerPoints += 5;
- }
- else if (targetsArrayInt[startIndexLeft] - 5 < 5)
- {
- playerPoints += targetsArrayInt[startIndexLeft];
- targetsArrayInt[startIndexLeft] = 0;
- }
- }
- break;
- case 'R':
- string[] commandRight = commandArray[1].Split('@');
- int startIndexRight = int.Parse(commandRight[1]);
- int lengthRight = int.Parse(commandRight[2]);
- if (startIndexRight >= 0 && startIndexRight < targetsArrayInt.Length)
- {
- for (int j = 0; j < lengthRight; j++)
- {
- startIndexRight++;
- if (startIndexRight == targetsArrayInt.Length)
- {
- startIndexRight = 0;
- }
- }
- if (targetsArrayInt[startIndexRight] - 5 >= 5)
- {
- targetsArrayInt[startIndexRight] -= 5;
- playerPoints += 5;
- }
- else if (targetsArrayInt[startIndexRight] - 5 < 5)
- {
- playerPoints += targetsArrayInt[startIndexRight];
- targetsArrayInt[startIndexRight] = 0;
- }
- }
- break;
- }
- break;
- case "Reverse":
- int[] temp = new int[targetsArrayInt.Length];
- int num = 0;
- for (int i = targetsArrayInt.Length - 1; i >= 0; i--)
- {
- temp[num] = targetsArrayInt[i];
- num++;
- }
- targetsArrayInt = temp;
- break;
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" - ", targetsArrayInt));
- Console.WriteLine($"Iskren finished the archery tournament with {playerPoints} points!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement