emilangelo

Icarus

Apr 13th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Icarus
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         const string endCommand = "Supernova";
  9.         int codedDirection = 0;
  10.  
  11.         int[] plane = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.         int currPoss = int.Parse(Console.ReadLine());
  13.  
  14.         int currDamm = 1;
  15.  
  16.         string[] commandArgs = Console.ReadLine().Split();
  17.  
  18.         while (commandArgs[0] != endCommand)
  19.         {
  20.             string direction = commandArgs[0];
  21.             int steps = int.Parse(commandArgs[1]);
  22.  
  23.             if (direction == "left") codedDirection = -1;
  24.             else codedDirection = 1;
  25.  
  26.             for (int i = 0; i < steps; i++)
  27.             {
  28.                 currPoss += codedDirection;
  29.  
  30.                 if (currPoss < 0)
  31.                 {
  32.                     currPoss = plane.Length - 1;
  33.                     currDamm++;
  34.                 }
  35.                 else if (currPoss > plane.Length - 1)
  36.                 {
  37.                     currPoss = 0;
  38.                     currDamm++;
  39.                 }
  40.                 plane[currPoss] -= currDamm;
  41.             }
  42.            commandArgs = Console.ReadLine().Split();
  43.         }
  44.         Console.WriteLine(String.Join(' ', plane));
  45.     }
  46. }
Add Comment
Please, Sign In to add comment