Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- var array = Console.ReadLine().Split('|').Select(int.Parse).ToArray();
- var totalPoints = 0;
- string command = Console.ReadLine();
- while (command != "Game over")
- {
- if (command.Contains("Left"))
- {
- var startIndex = int.Parse(command.Split('@')[1]);
- var lenght = int.Parse(command.Split('@')[2]);
- //to the left from {start index} with given {length}.
- if (startIndex - lenght < 0)
- {
- startIndex = Math.Abs(startIndex - lenght);
- if (array.Length - lenght < 0)
- {
- lenght = Math.Abs( array.Length - lenght);
- if (array.Length - lenght < 0)
- {
- lenght= Math.Abs(array.Length - lenght);
- }
- if (array[array.Length - lenght] >= 5)
- {
- array[array.Length - lenght] -= 5;
- totalPoints += 5;
- }
- else
- {
- var target = array[startIndex];
- totalPoints += target;
- array[target] = 0;
- }
- command = Console.ReadLine();
- continue;
- }
- var pointsAtArray = array[array.Length - lenght];//index
- if (array[array.Length - lenght] >= 5)
- {
- array[array.Length - lenght] -= 5;
- totalPoints += 5;
- }
- else
- {
- var target = array[startIndex];
- totalPoints += target;
- array[target] = 0;
- }
- //totalPoints += Math.Abs(array[array.Length - lenght] - 5);
- //array[array.Length - lenght] -= 5;
- }
- }
- else if (command.Contains("Right"))
- {
- var startIndex = int.Parse(command.Split('@')[1]);
- var lenght = int.Parse(command.Split('@')[2]);
- // not sure about >=/>
- if (array.Length >= startIndex + lenght)
- {
- array[startIndex + lenght + 1] -= 5;
- totalPoints += 5;
- }
- else
- {
- lenght = Math.Abs(array.Length - (startIndex + lenght));
- startIndex = 0;
- if (array.Length < lenght)
- {
- command = Console.ReadLine();
- continue;
- //lenght = Math.Abs(array.Length - lenght);
- }
- if (array[lenght] >= 5)
- {
- array[lenght] -= 5;
- totalPoints += 5;
- }
- else
- {
- var points = Math.Abs(array[lenght] - 5);
- totalPoints += points;
- array[lenght] = 0;
- }
- }
- }
- else if (command == "Reverse")
- {
- array = array.Reverse().ToArray();
- }
- command = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" - ", array));
- Console.WriteLine($"Iskren finished the archery tournament with {totalPoints} points!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement