Advertisement
_CodeBehind

LadybugsShit

Feb 15th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.60 KB | None | 0 0
  1. namespace _02.Ladybugs
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             int fieldSize = int.Parse(Console.ReadLine());
  11.             int[] indexesWithBugs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.             int[] field = new int[fieldSize];
  13.  
  14.             for (int i = 0; i < fieldSize; i++)
  15.             {
  16.                 if (indexesWithBugs.Contains(i))
  17.                 {
  18.                     field[i] = 1;
  19.                 }
  20.                 else
  21.                 {
  22.                     field[i] = 0;
  23.                 }
  24.             }
  25.  
  26.             string[] command = Console.ReadLine().Split(' ').ToArray();
  27.  
  28.             while (command[0] != "end")
  29.             {
  30.                 int index = int.Parse(command[0]);
  31.                 int moving = int.Parse(command[2]);
  32.  
  33.                 if (index < 0 || index >= field.Length)
  34.                 {
  35.                     command = Console.ReadLine().Split();
  36.                     continue;
  37.                 }
  38.                 else if (field[index] == 0)
  39.                 {
  40.                     command = Console.ReadLine().Split();
  41.                     continue;
  42.                 }
  43.                 else if (field[index] == 1)
  44.                 {
  45.                     if (command[1] == "right")
  46.                     {
  47.                         if (moving > 0)
  48.                         {
  49.                             if (index + moving >= field.Length)
  50.                             {
  51.                                 field[index] = 0;
  52.                             }
  53.                             else
  54.                             {
  55.                                 field[index] = 0;
  56.                                 for (int i = index + moving; i < field.Length; i += moving)
  57.                                 {
  58.                                     if (field[i] == 1)
  59.                                     {
  60.                                         continue;
  61.                                     }
  62.                                     else
  63.                                     {
  64.                                         field[i] = 1;
  65.                                         break;
  66.                                     }
  67.  
  68.                                 }
  69.                             }
  70.                         }
  71.                         else if (moving < 0)
  72.                         {
  73.                             Math.Abs(moving);
  74.                             if (index - moving < 0)
  75.                             {
  76.                                 field[index] = 0;
  77.                             }
  78.                             else
  79.                             {
  80.                                 field[index] = 0;
  81.  
  82.                                 for (int i = index - moving; i > -1; i -= moving)
  83.                                 {
  84.  
  85.                                     if (field[i] == 1)
  86.                                     {
  87.                                         continue;
  88.                                     }
  89.                                     else
  90.                                     {
  91.                                         field[i] = 1;
  92.                                         break;
  93.                                     }
  94.                                 }
  95.                             }
  96.                         }
  97.                     }
  98.                     else if (command[1] == "left")
  99.                     {
  100.                         if (moving > 0)
  101.                         {
  102.                             if (index - moving < 0)
  103.                             {
  104.                                 field[index] = 0;
  105.                             }
  106.                             else
  107.                             {
  108.                                 field[index] = 0;
  109.  
  110.                                 for (int i = index - moving; i > -1; i -= moving)
  111.                                 {
  112.  
  113.                                     if (field[i] == 1)
  114.                                     {
  115.                                         continue;
  116.                                     }
  117.                                     else
  118.                                     {
  119.                                         field[i] = 1;
  120.                                         break;
  121.                                     }
  122.                                 }
  123.                             }
  124.                         }
  125.                         else if (moving < 0)
  126.                         {
  127.                             Math.Abs(moving);
  128.                             if (index + moving >= field.Length)
  129.                             {
  130.                                 field[index] = 0;
  131.                             }
  132.                             else
  133.                             {
  134.                                 field[index] = 0;
  135.                                 for (int i = index + moving; i < field.Length; i += moving)
  136.                                 {
  137.                                     if (field[i] == 1)
  138.                                     {
  139.                                         continue;
  140.                                     }
  141.                                     else
  142.                                     {
  143.                                         field[i] = 1;
  144.                                         break;
  145.                                     }
  146.  
  147.                                 }
  148.                             }
  149.                         }
  150.                     }
  151.                     command = Console.ReadLine().Split(' ').ToArray();
  152.                 }
  153.             }
  154.             Console.WriteLine(string.Join(" ", field));
  155.  
  156.         }
  157.  
  158.        
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement