Advertisement
ZhivkoPetkov

Ladybugs

May 29th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ladybug
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var size = int.Parse(Console.ReadLine());
  11.             var startindexes = Console.ReadLine().Split().Select(int.Parse).Where(x => x >= 0 && x < size).ToList();
  12.             var field = new int[size];
  13.  
  14.             foreach (var item in startindexes)
  15.             {
  16.                 field[item] = 1;
  17.             }
  18.  
  19.             while (true)
  20.             {
  21.                 var input = Console.ReadLine().Split().ToList();
  22.  
  23.                 if (input[0] == "end")
  24.                 {
  25.                     break;
  26.                 }
  27.  
  28.                 var start = long.Parse(input[0]);
  29.                 var direction = input[1];
  30.                 var steps = long.Parse(input[2]);
  31.  
  32.                 if (start < 0 || start >= size|| steps > size)
  33.                 {
  34.                     continue;
  35.  
  36.                 }
  37.  
  38.                 else if (field[start] == 0)
  39.                 {
  40.                     continue;
  41.                 }
  42.  
  43.                 else
  44.                 {
  45.                     field[start] = 0;
  46.                     if (direction == "left")
  47.                     {
  48.                         steps *= -1;
  49.                     }
  50.  
  51.                     long destination = start;
  52.  
  53.                     while (true)
  54.                     {
  55.                         if (destination + steps >= size)
  56.                         {
  57.                             break;
  58.                         }
  59.  
  60.                         destination += steps;
  61.  
  62.                         if (field[destination] == 1)
  63.                         {
  64.                             continue;
  65.                         }
  66.  
  67.                         else
  68.                         {
  69.                             field[destination] = 1;
  70.                             break;
  71.                         }
  72.  
  73.                     }
  74.                 }
  75.             }
  76.             Console.WriteLine(String.Join(" ", field));
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement