Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace MethoodsAndStrings
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int position = int.Parse(Console.ReadLine());
- int[] path = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
- string[] commands = Console.ReadLine().Split(' ');
- long sumForeword = 0;
- long sumBackwords = 0;
- while (commands[0] != "exit")
- {
- int steps = int.Parse(commands[0]);
- string direction = commands[1];
- int size = int.Parse(commands[2]);
- if (direction == "forward")
- {
- while(steps>0)
- {
- if (position + size >= path.Length)
- {
- position = position + size - path.Length;
- }
- else
- {
- position += size;
- }
- sumForeword += path[position];
- steps--;
- }
- }
- else if (direction == "backwards")
- {
- while (steps > 0)
- {
- if (position - size < 0)
- {
- position = position - size + path.Length;
- }
- else
- {
- position -= size;
- }
- sumBackwords += path[position];
- steps--;
- }
- }
- commands = Console.ReadLine().Split(' ');
- }
- Console.WriteLine($"Forward: {sumForeword}");
- Console.WriteLine($"Backwards: {sumBackwords}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement