Advertisement
Grimmjow1

LadyBugs

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