Advertisement
Aborigenius

LadyBug With Errors

Aug 30th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 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.  
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             int inputSize = int.Parse(Console.ReadLine());
  17.             int[] Field = new int[inputSize];
  18.             int[] LBindexes = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  19.             for (int i = 0; i < LBindexes.Length; i++)
  20.             {
  21.                 if (LBindexes[i] <= Field.Length)
  22.                 {
  23.                     Field[LBindexes[i]] = 1;
  24.                 }
  25.  
  26.             }
  27.             var list = Field.ToList();
  28.  
  29.             string inp = Console.ReadLine();
  30.             while (inp != "end")
  31.             {
  32.                 string[] input = inp.Split(' ');
  33.                 int ladybug = int.Parse(input[0]);
  34.                 string direction = input[1];
  35.                 int howMouchToMove = int.Parse(input[2]);
  36.                 int indexA = ladybug;
  37.                 if (howMouchToMove < 0)
  38.                 {
  39.                     howMouchToMove *= -1;
  40.                     switch (direction)
  41.                     {
  42.                         case "left":
  43.                             direction = "right";
  44.                             break;
  45.  
  46.                         case "right":
  47.                             direction = "left";
  48.                             break;
  49.                     }
  50.                 }
  51.                 if (direction == "left")
  52.                 {
  53.                     int indexB = indexA - howMouchToMove;
  54.                     if (indexB > list.Count || indexB < list.First())
  55.                     {
  56.                         list[indexA] = 0;
  57.                         goto Input;
  58.                     }
  59.                     if (list.ElementAt(indexB) != 0)
  60.                     {
  61.                         indexB += indexB;
  62.                     }
  63.                     //      Console.WriteLine("Moving bug {0} to {1}", indexA, indexB);
  64.                     Swap(list, indexA, indexB);
  65.                 }
  66.                 if (direction == "right")
  67.                 {
  68.  
  69.                     int indexB = indexA + howMouchToMove;
  70.                     if (list.ElementAt(indexB) != 0 && indexB < list.Count)
  71.                     {
  72.                         indexB += indexB;
  73.                     }
  74.                     if (indexB > list.Count || indexB > list.First())
  75.                     {
  76.                         list[indexA] = 0;
  77.                         Console.WriteLine("FU!");
  78.                     }
  79.                     else
  80.                     {
  81.  
  82.                         Swap(list, indexA, indexB);
  83.                         Console.WriteLine("Moving bug {0} to {1}", indexA, indexB);
  84.                     }
  85.  
  86.  
  87.                 }
  88.                 Input:
  89.                 inp = Console.ReadLine();
  90.             }
  91.  
  92.             foreach (var item in list)
  93.             {
  94.                 Console.Write(item + " ");
  95.             }
  96.             Console.WriteLine();
  97.         }
  98.         static void Swap(List<int> list, int indexA, int indexB)
  99.         {
  100.             int tmp = list[indexA];
  101.             list[indexA] = list[indexB];
  102.             list[indexB] = tmp;
  103.         }
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement