vandeva

Ladybugs Fly

Jun 4th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Numerics;
  4.  
  5. namespace Ladybugs_Fly
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int fieldSize = int.Parse(Console.ReadLine());
  12.  
  13.             long[] initialIndexes = Console.ReadLine().Split().Select(long.Parse).ToArray();
  14.  
  15.             long[] ladybugsPositions = new long[fieldSize];
  16.  
  17.             for (long i = 0; i < fieldSize; i++)
  18.             {
  19.                 for (long m = 0; m < initialIndexes.Length; m++)
  20.                 {
  21.                     if (initialIndexes.Contains(i))
  22.                     {
  23.                         ladybugsPositions[i] = 1;
  24.                     }
  25.                 }
  26.             }
  27.             string input = Console.ReadLine();
  28.  
  29.             while (input != "end")
  30.             {
  31.                 string[] command = input.Split(" ");
  32.  
  33.                 long currentLadybugIndex = long.Parse(command[0]);
  34.                 string direction = command[1];
  35.                 long flyLength = long.Parse(command[2]);
  36.  
  37.                 if (fieldSize > 0 && currentLadybugIndex < ladybugsPositions.Length && ladybugsPositions[currentLadybugIndex] == 1)
  38.                 {
  39.                     ladybugsPositions[currentLadybugIndex] = 0;
  40.                         if (direction == "right")
  41.                         {
  42.                             if (currentLadybugIndex + flyLength < ladybugsPositions.Length)
  43.                             {
  44.                                 while (ladybugsPositions[currentLadybugIndex + flyLength] != 0
  45.                                 && currentLadybugIndex + flyLength < ladybugsPositions.Length - 1)
  46.                                 {
  47.                                     currentLadybugIndex += flyLength;
  48.                                 }
  49.                                 if (ladybugsPositions[currentLadybugIndex + flyLength] == 0)
  50.                                 {
  51.                                     ladybugsPositions[currentLadybugIndex + flyLength] = 1;
  52.                                 }
  53.                             }
  54.                         }
  55.                         else if (direction == "left")
  56.                         {
  57.                             if (currentLadybugIndex - flyLength >= 0 && currentLadybugIndex - flyLength < ladybugsPositions.Length)
  58.                             {
  59.                                 while (ladybugsPositions[currentLadybugIndex - flyLength] != 0
  60.                                     && currentLadybugIndex - flyLength >= 0
  61.                                     && currentLadybugIndex - flyLength < ladybugsPositions.Length - 1)
  62.                                 {
  63.                                     currentLadybugIndex -= flyLength;
  64.                                 }
  65.                                 if (ladybugsPositions[currentLadybugIndex - flyLength] == 0)
  66.                                 {
  67.                                     ladybugsPositions[currentLadybugIndex - flyLength] = 1;
  68.                                 }
  69.                             }
  70.                         }
  71.  
  72.                    
  73.                 }
  74.                 input = Console.ReadLine();
  75.             }
  76.             Console.WriteLine(string.Join(" ", ladybugsPositions));
  77.          }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment