Advertisement
BSO90

Move

Jul 1st, 2021
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Move
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int startingPoint = int.Parse(Console.ReadLine());
  11.             int[] numbers = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
  12.             string[] command = Console.ReadLine().Split();
  13.             int sumForward = 0;
  14.             int sumBackward = 0;
  15.             int index = 0;
  16.             while (command[0] != "exit")
  17.             {
  18.                 int step = int.Parse(command[0]);
  19.                 string direction = command[1];
  20.                 int size = int.Parse(command[2]);
  21.                 if (direction == "forward")
  22.                 {
  23.                     while (step != 0)
  24.                     {
  25.                         index = startingPoint + size;
  26.                         while (index >= numbers.Length)
  27.                         {
  28.                             index -= numbers.Length;
  29.                         }
  30.  
  31.                         sumForward += numbers[index];
  32.                         startingPoint = index;
  33.                         step--;
  34.                     }
  35.                 }
  36.                    
  37.                 else
  38.                 {
  39.                     while (step != 0)
  40.                     {
  41.                         index = startingPoint - size;
  42.                         while (index < 0)
  43.                         {
  44.                             index += numbers.Length;
  45.                         }
  46.  
  47.                         sumBackward += numbers[index];
  48.                         startingPoint = index;
  49.                         step--;
  50.                     }
  51.                 }
  52.  
  53.                 command = Console.ReadLine().Split();
  54.             }
  55.  
  56.             Console.WriteLine($"Forward: {sumForward}");
  57.             Console.WriteLine($"Backwards: {sumBackward}");
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63.                    
  64.  
  65.                    
  66.            
  67.  
  68.                    
  69.  
  70.  
  71.  
  72.  
  73.  
  74.                
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement