Advertisement
stanevplamen

02.09.02.03.Laser

Jun 19th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. using System;
  2.  
  3. class Laser
  4. {
  5.     static void Main()
  6.     {
  7.         string cubeInput = Console.ReadLine(); // "5 10 5"; //
  8.         string[] splitedArray = cubeInput.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  9.  
  10.         int width = int.Parse(splitedArray[0]);
  11.         int heigth = int.Parse(splitedArray[1]);
  12.         int depth = int.Parse(splitedArray[2]);
  13.  
  14.         string start = Console.ReadLine(); // "2 6 3"; //
  15.         string[] startPosition = start.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  16.         int startWidth = int.Parse(startPosition[0]) - 1;
  17.         int startHeigth = int.Parse(startPosition[1]) - 1;
  18.         int startDepth = int.Parse(startPosition[2]) - 1;
  19.  
  20.         string direction = Console.ReadLine(); // "1 0 1"; //
  21.         string[] dirPosition = direction.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  22.         dirWidth = int.Parse(dirPosition[0]);
  23.         dirHeigth = int.Parse(dirPosition[1]);
  24.         dirDepth = int.Parse(dirPosition[2]);
  25.  
  26.         byte[, ,] theMatrix = LoadTheMatrix(width, heigth, depth);
  27.  
  28.         FindPathToExit(startWidth, startHeigth, startDepth);
  29.     }
  30.  
  31.     static int dirWidth;
  32.     static int dirHeigth;
  33.     static int dirDepth;
  34.  
  35.     static byte[, ,] theMatrix;
  36.  
  37.     static byte[, ,] LoadTheMatrix(int width, int heigth, int depth)
  38.     {
  39.         theMatrix = new byte[width, heigth, depth];
  40.         for (int w = 0; w < theMatrix.GetLength(0); w++)
  41.         {
  42.             for (int h = 0; h < theMatrix.GetLength(1); h++)
  43.             {
  44.                 for (int d = 0; d < theMatrix.GetLength(2); d++)
  45.                 {
  46.                     if ((w == 0 && h == 0) || (h == 0 && d == 0) || (d == 0 && w == 0) ||
  47.                         (w == theMatrix.GetLength(0) - 1 && h == theMatrix.GetLength(1) - 1) ||
  48.                         (h == theMatrix.GetLength(1) - 1 && d == theMatrix.GetLength(2) - 1) ||
  49.                         (d == theMatrix.GetLength(2) - 1 && w == theMatrix.GetLength(0) - 1))
  50.                     {
  51.                         theMatrix[w, h, d] = 1;
  52.                     }
  53.                     else
  54.                     {
  55.                         theMatrix[w, h, d] = 0;
  56.                     }
  57.                 }
  58.             }
  59.         }
  60.         return theMatrix;
  61.     }
  62.  
  63.     static int tempW; static int tempH; static int tempD;
  64.  
  65.      static void FindPathToExit(int currentWidth, int currentHeigth, int currentDepth)
  66.      {
  67.          // check if we can move
  68.          if (theMatrix[currentWidth, currentHeigth, currentDepth] == 1)
  69.          {
  70.              Console.WriteLine("{0} {1} {2}", tempW + 1, tempH + 1, tempD + 1);
  71.              Environment.Exit(0);
  72.          }
  73.          // check if we need to change direction
  74.          if (currentWidth <= 0 || currentWidth >= theMatrix.GetLength(0) - 1)
  75.          {
  76.              dirWidth *= (-1);
  77.          }
  78.          if (currentHeigth <= 0 || currentHeigth >= theMatrix.GetLength(1) - 1)
  79.          {
  80.              dirHeigth *= (-1);
  81.          }
  82.          if (currentDepth <= 0 || currentDepth >= theMatrix.GetLength(2) - 1)
  83.          {
  84.              dirDepth *= (-1);
  85.          }
  86.  
  87.  
  88.          // moving
  89.          if (theMatrix[currentWidth, currentHeigth, currentDepth] == 0)
  90.          {
  91.              tempW = currentWidth; tempH = currentHeigth; tempD = currentDepth;
  92.              theMatrix[currentWidth, currentHeigth, currentDepth] = 1;
  93.              FindPathToExit(currentWidth + dirWidth, currentHeigth + dirHeigth, currentDepth + dirDepth);
  94.          }
  95.  
  96.      }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement