Created
December 3, 2016 07:46
-
-
Save nasko90/31049bc6f40fa3c7aa01bd2ca01e6288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Data; | |
namespace Methods | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
string numbers = Console.ReadLine(); | |
string instructions = ""; | |
int times = 0; | |
int steps = 0; | |
bool parse; | |
int[] numArray = numbers.Split(' ').Select(c => Convert.ToInt32(c.ToString())).ToArray(); | |
int startingPosition = 0; | |
double value = 0; | |
int position = 0; | |
double result = 0; | |
double rounds = 0; | |
int positionOut = 0; | |
int changeSteps = 0; | |
while (true) | |
{ | |
instructions = Console.ReadLine(); | |
if (instructions == "stop") | |
{ | |
break; | |
} | |
rounds++; | |
string[] instructionsToArray = instructions.Split(' '); | |
parse = Int32.TryParse(instructionsToArray[0], out times); | |
parse = Int32.TryParse(instructionsToArray[2], out steps); | |
int count = 0; | |
bool isRightDirection = true; | |
if (instructionsToArray[1] == "left") | |
{ | |
isRightDirection = false; | |
} | |
if (isRightDirection) | |
{ | |
for (position = startingPosition; count < times; count++) | |
{ | |
positionOut += steps; | |
if (positionOut >= numArray.Length) | |
{ | |
if (steps>numArray.Length) | |
{ | |
changeSteps = steps % numArray.Length; | |
} | |
else | |
{ | |
changeSteps = steps; | |
} | |
for (int i = 0; i < changeSteps; i++) | |
{ | |
position++; | |
if (position==numArray.Length) | |
{ | |
position = 0; | |
} | |
} | |
positionOut = position; | |
} | |
else | |
{ | |
position = positionOut; | |
} | |
value += numArray[position]; | |
} | |
} | |
else | |
{ | |
for (position = startingPosition; count < times; count++) | |
{ | |
positionOut -= steps; | |
if (positionOut < 0) | |
{ | |
if (steps > numArray.Length) | |
{ | |
changeSteps = steps % numArray.Length; | |
} | |
else | |
{ | |
changeSteps = steps; | |
} | |
for (int i = 0; i < changeSteps; i++) | |
{ | |
position--; | |
if (position == -1) | |
{ | |
position = numArray.Length-1; | |
} | |
} | |
positionOut = position; | |
} | |
else | |
{ | |
position = positionOut; | |
} | |
value += numArray[position]; | |
} | |
} | |
startingPosition = position; | |
} | |
result = value / rounds; | |
Console.WriteLine(result.ToString("0.0")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment