Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Ladybugs
  5. {
  6.     public class Ladybugs
  7.     {
  8.         public static void Main()
  9.         {
  10.             int arrLength = int.Parse(Console.ReadLine());
  11.             int[] ladybugs = new int[arrLength];
  12.  
  13.             int[] indexes = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             string[] command = Console.ReadLine().Split();
  15.  
  16.             foreach (var index in indexes)
  17.             {
  18.                 if (index >= 0  && index < arrLength)
  19.                 {
  20.                     ladybugs[index] = 1;
  21.                 }              
  22.             }
  23.  
  24.             while (!command[0].Equals("end"))
  25.             {
  26.                 long index = long.Parse(command[0]);
  27.                 long count = long.Parse(command[2]);
  28.  
  29.                 if (index < 0 || index >= arrLength)
  30.                 {
  31.                     command = Console.ReadLine().Split();
  32.                     continue;
  33.                 }
  34.  
  35.                 if (ladybugs[index] == 0)
  36.                 {
  37.                     command = Console.ReadLine().Split();
  38.                     continue;
  39.                 }
  40.  
  41.                 if (command[1].Equals("right"))
  42.                 {
  43.                     if (index + count >= arrLength || index + count < 0)
  44.                     {
  45.                         ladybugs[index] = 0;
  46.                         command = Console.ReadLine().Split();
  47.                         continue;
  48.                     }
  49.                     else
  50.                     {
  51.                         long flyDistance = index + count;
  52.                         ladybugs[index] = 0;
  53.                         while (index < arrLength && index >= 0 && flyDistance < arrLength && flyDistance >= 0)
  54.                         {
  55.                             if (ladybugs[flyDistance] == 0)
  56.                             {
  57.                                 ladybugs[flyDistance] = 1;
  58.                                 break;
  59.                             }
  60.                             else
  61.                             {
  62.                                 flyDistance += count;
  63.                             }                          
  64.                         }
  65.                     }
  66.                 }
  67.                 else if (command[1].Equals("left"))
  68.                 {
  69.                     if (index - count >= arrLength || index - count < 0)
  70.                     {
  71.                         ladybugs[index] = 0;
  72.                         command = Console.ReadLine().Split();
  73.                         continue;
  74.                     }
  75.                     else
  76.                     {
  77.                         ladybugs[index] = 0;
  78.                         long flyDistance = index - count;
  79.  
  80.                         while (index < arrLength && index >= 0 && flyDistance < arrLength && flyDistance >= 0)
  81.                         {
  82.                             if (ladybugs[flyDistance] == 0)
  83.                             {
  84.                                 ladybugs[flyDistance] = 1;
  85.                                 break;
  86.                             }
  87.                             else
  88.                             {
  89.                                 flyDistance -= count;
  90.                             }
  91.                         }
  92.                     }
  93.                 }
  94.  
  95.                 command = Console.ReadLine().Split();
  96.             }
  97.  
  98.             Console.WriteLine(string.Join(" ", ladybugs));
  99.  
  100.  
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement