Advertisement
Guest User

Untitled

a guest
Aug 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Ladybugs
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int fieldSize = int.Parse(Console.ReadLine());
  12.             string unseparatedIndexes = Console.ReadLine();
  13.             int[] ladybugIndexes = unseparatedIndexes
  14.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  15.                 .Select(int.Parse)
  16.                 .ToArray();
  17.  
  18.             var lady = new int[fieldSize];
  19.  
  20.             for (int i = 0; i < ladybugIndexes.Length; i++)
  21.             {
  22.                 lady[ladybugIndexes[i]] = 1;
  23.             }
  24.  
  25.             string moves = Console.ReadLine();
  26.  
  27.             while (moves != "end")
  28.             {
  29.                 string[] splitedInput = moves.Split().ToArray();
  30.  
  31.                 long ladybugIndex = long.Parse(splitedInput[0]);
  32.                 string direction = splitedInput[1];
  33.                 long flyLength = long.Parse(splitedInput[2]);
  34.  
  35.                 if (direction == "right")
  36.                 {
  37.                     while (true)
  38.                     {
  39.                         lady[ladybugIndex] = 0;
  40.  
  41.                        
  42.                         if (ladybugIndex + flyLength + 1 > lady.Length)
  43.                         {
  44.                             break;
  45.                         }
  46.                         else if(lady[ladybugIndex + flyLength] == 0)
  47.                         {
  48.                             lady[ladybugIndex + flyLength] = 1;
  49.                             break;
  50.                         }
  51.                         else
  52.                         {
  53.                             for (long i = ladybugIndex; i < lady.Length - 1; i++)
  54.                             {
  55.                                 if (lady[i + 1] == 0)
  56.                                 {
  57.                                     lady[i + 1] = 1;
  58.                                     break;
  59.                                 }
  60.                             }
  61.                         }
  62.                         break;
  63.                     }
  64.                    
  65.                 }
  66.                 else
  67.                 {
  68.                     while (true)
  69.                     {
  70.                         lady[ladybugIndex] = 0;
  71.  
  72.  
  73.                         if (ladybugIndex - flyLength - 1 > lady.Length)
  74.                         {
  75.                             break;
  76.                         }
  77.                         else if (lady[ladybugIndex - flyLength] == 0)
  78.                         {
  79.                             lady[ladybugIndex - flyLength] = 1;
  80.                             break;
  81.                         }
  82.                         else
  83.                         {
  84.                             for (long i = ladybugIndex; i < lady.Length - 1; i--)
  85.                             {
  86.                                 if (lady[i - 1] == 0)
  87.                                 {
  88.                                     lady[i - 1] = 1;
  89.                                     break;
  90.                                 }
  91.                             }
  92.                         }
  93.                         break;
  94.                     }
  95.                 }
  96.  
  97.                 moves = Console.ReadLine();
  98.             }
  99.  
  100.             Console.WriteLine(string.Join(" ", lady));
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement