Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Move
- {
- class Program
- {
- static void Main(string[] args)
- {
- int startingPoint = int.Parse(Console.ReadLine());
- int[] numbers = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
- string[] command = Console.ReadLine().Split();
- int sumForward = 0;
- int sumBackward = 0;
- int index = 0;
- while (command[0] != "exit")
- {
- int step = int.Parse(command[0]);
- string direction = command[1];
- int size = int.Parse(command[2]);
- if (direction == "forward")
- {
- while (step != 0)
- {
- index = startingPoint + size;
- while (index >= numbers.Length)
- {
- index -= numbers.Length;
- }
- sumForward += numbers[index];
- startingPoint = index;
- step--;
- }
- }
- else
- {
- while (step != 0)
- {
- index = startingPoint - size;
- while (index < 0)
- {
- index += numbers.Length;
- }
- sumBackward += numbers[index];
- startingPoint = index;
- step--;
- }
- }
- command = Console.ReadLine().Split();
- }
- Console.WriteLine($"Forward: {sumForward}");
- Console.WriteLine($"Backwards: {sumBackward}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement