tsekotsolov

P02.Icarus

Oct 29th, 2017
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P02__Icarus
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             var inputList = Console.ReadLine().Split().Select(int.Parse).ToList();
  11.             int indexPosition = int.Parse(Console.ReadLine());
  12.             int damage = 1;
  13.             var moves = Console.ReadLine();
  14.  
  15.             while (moves != "Supernova")
  16.             {
  17.                 var movesSplited = moves.Split(' ').ToArray();
  18.                 var direction = movesSplited.First();
  19.                 var steps = int.Parse(movesSplited[1]);
  20.  
  21.                 if (direction == "left" && steps != 0)
  22.                 {
  23.                     for (int i = 1; i <= steps; i++)
  24.                     {
  25.                         if (indexPosition <= 0)
  26.                         {
  27.                             damage++;
  28.                             indexPosition = inputList.Count;
  29.                         }
  30.  
  31.                         inputList[indexPosition - 1] -= damage;
  32.                         indexPosition--;
  33.                     }
  34.                 }
  35.                 else if (direction == "right" && steps != 0)
  36.                 {
  37.                     for (int i = 1; i <= steps; i++)
  38.                     {
  39.                         if (indexPosition >= inputList.Count - 1)
  40.                         {
  41.                             damage++;
  42.                             indexPosition = -1;
  43.                         }
  44.  
  45.                         inputList[indexPosition + 1] -= damage;
  46.                         indexPosition++;
  47.                     }
  48.                 }
  49.                 moves = Console.ReadLine();
  50.             }
  51.  
  52.             Console.WriteLine(string.Join(" ", inputList));
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment