simonradev

asdasd

Dec 7th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LadyBugs
  8. {
  9.     class Program
  10.     {
  11.         public static int[] ladyBugs;
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             int sizeOfTheField = int.Parse(Console.ReadLine());
  16.             ladyBugs = new int[sizeOfTheField];
  17.  
  18.             int[] ladyBugsPositions = Console.ReadLine().Split().Select(int.Parse).
  19.                 Where(x => x >= 0 && x < sizeOfTheField).ToArray();
  20.  
  21.             foreach (int currPositioning in ladyBugsPositions)
  22.             {
  23.                 ladyBugs[currPositioning] = 1;
  24.             }
  25.  
  26.             string inputLine = Console.ReadLine();
  27.             while (!inputLine.Equals("end"))
  28.             {
  29.                 string[] positioningInfo = inputLine.Split().ToArray();
  30.  
  31.                 int ladyBugIndex = int.Parse(positioningInfo[0]);
  32.                 string direction = positioningInfo[1].ToLower();
  33.                 int flyLenght = int.Parse(positioningInfo[2]);
  34.  
  35.                 if (direction.Equals("right"))
  36.                 {
  37.                     MoveTheChosenBugToTheLeft(ladyBugIndex, flyLenght);
  38.                 }
  39.                 else
  40.                 {
  41.  
  42.                 }
  43.  
  44.                 inputLine = Console.ReadLine();
  45.             }
  46.  
  47.             Console.WriteLine(string.Join(" ", ladyBugs));
  48.         }
  49.  
  50.         private static void MoveTheChosenBugToTheLeft(int ladyBugIndex, int flyLenght)
  51.         {
  52.             bool isFinishedMoingAround = false;
  53.             while (!isFinishedMoingAround && ladyBugs[ladyBugIndex] != 0)
  54.             {
  55.                 if (ladyBugIndex + flyLenght >= ladyBugs.Length)
  56.                 {
  57.                     ladyBugs[ladyBugIndex] = 0;
  58.  
  59.                     isFinishedMoingAround = true;
  60.                     break;
  61.                 }
  62.  
  63.                 if (ladyBugs[ladyBugIndex + flyLenght] == 0)
  64.                 {
  65.                     ladyBugs[ladyBugIndex] = 0;
  66.                     ladyBugs[ladyBugIndex + flyLenght] = 1;
  67.  
  68.                     isFinishedMoingAround = true;
  69.                     break;
  70.                 }
  71.  
  72.                 if (ladyBugs[ladyBugIndex + flyLenght] == 1)
  73.                 {
  74.                     flyLenght += flyLenght;
  75.                 }
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment