Advertisement
AdelinaMladenova

LadyBugs

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