Advertisement
Ivo123

Untitled

Sep 1st, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.31 KB | None | 0 0
  1. using System;
  2.  
  3. class Slides
  4. {
  5.     public static string[, ,] cube;
  6.     public static int widthOfCube, heightOfCube, depthOfCube, ballsWidth, ballsHeight, ballsDepth;
  7.     public static int[] dimensionsOfTheCube;
  8.  
  9.     static void Main()
  10.     {
  11.         dimensionsOfTheCube = EnteringDimensionsForCube();
  12.         widthOfCube = dimensionsOfTheCube[0];
  13.         heightOfCube = dimensionsOfTheCube[1];
  14.         depthOfCube = dimensionsOfTheCube[2];
  15.  
  16.         cube = new string[widthOfCube, heightOfCube, depthOfCube];
  17.         cube = EnteringDataForTheCube(cube);
  18.         int[] ballsLocation = EnteringBallsDimensions();
  19.         ballsWidth = ballsLocation[0];
  20.         ballsDepth = ballsLocation[1];
  21.         ballsHeight = 0;
  22.  
  23.         while (true)
  24.         {
  25.             string currentCell = cube[ballsWidth, ballsHeight, ballsDepth];
  26.  
  27.             string[] commandAndDirection = currentCell.Split();
  28.             string command = commandAndDirection[0];
  29.  
  30.             switch (command)
  31.             {
  32.                 case "S":
  33.                     SlidingTheBall(commandAndDirection[1]);
  34.                     break;
  35.                 case "T":
  36.                     ballsWidth = int.Parse(commandAndDirection[1]);
  37.                     ballsDepth = int.Parse(commandAndDirection[2]);
  38.                     break;
  39.                 case "E":
  40.                     if (ballsHeight == dimensionsOfTheCube[1] - 1)
  41.                     {
  42.                         PrintintMessage();
  43.                         return;
  44.                     }
  45.                     else
  46.                     {
  47.                         ballsHeight++;
  48.                     }
  49.                     break;
  50.                 case "B":
  51.                     PrintintMessage();
  52.                     return;
  53.  
  54.                 default: throw new ArgumentException();
  55.             }
  56.         }
  57.     }
  58.  
  59.     private static void PrintintMessage()
  60.     {
  61.         string currentCell = cube[ballsWidth, ballsHeight, ballsDepth];
  62.  
  63.  
  64.         if ((currentCell == "B") || (ballsHeight != (dimensionsOfTheCube[1] - 1)))
  65.         {
  66.             Console.WriteLine("No");
  67.         }
  68.         else
  69.         {
  70.             Console.WriteLine("Yes");
  71.         }
  72.  
  73.         Console.WriteLine("{0} {1} {2}", ballsWidth, ballsHeight, ballsDepth);
  74.     }
  75.  
  76.     private static void SlidingTheBall(string direction)
  77.     {
  78.         switch (direction)
  79.         {
  80.             case "L":
  81.                 ballsWidth--;
  82.                 ballsHeight++;
  83.                 break;
  84.             case "R":
  85.                 ballsWidth++;
  86.                 ballsHeight++;
  87.                 break;
  88.             case "F":
  89.                 ballsDepth--;
  90.                 ballsHeight++;
  91.                 break;
  92.             case "B":
  93.                 ballsDepth++;
  94.                 ballsHeight++;
  95.                 break;
  96.             case "FL":
  97.                 ballsDepth--;
  98.                 ballsWidth--;
  99.                 ballsHeight++;
  100.                 break;
  101.             case "FR":
  102.                 ballsDepth--;
  103.                 ballsWidth++;
  104.                 ballsHeight++;
  105.                 break;
  106.             case "BL":
  107.                 ballsDepth++;
  108.                 ballsWidth--;
  109.                 ballsHeight++;
  110.                 break;
  111.             case "BR":
  112.                 ballsDepth++;
  113.                 ballsWidth++;
  114.                 ballsHeight++;
  115.                 break;
  116.  
  117.             default: throw new ArgumentException();
  118.         }
  119.  
  120.         if (!IsPassable())
  121.         {
  122.             Console.WriteLine("No");
  123.             Console.WriteLine("{0} {1} {2}", ballsWidth, ballsHeight, ballsDepth);
  124.             Environment.Exit(0);
  125.         }
  126.     }
  127.  
  128.     private static bool IsPassable()
  129.     {
  130.         if (ballsWidth >= 0 &&
  131.             ballsHeight >= 0 &&
  132.             ballsDepth >= 0 &&
  133.             ballsWidth < dimensionsOfTheCube[0] &&
  134.             ballsHeight < dimensionsOfTheCube[1] &&
  135.             ballsDepth < dimensionsOfTheCube[2])
  136.         {
  137.             return true;
  138.         }
  139.         else
  140.         {
  141.             return false;
  142.         }
  143.     }
  144.  
  145.     private static int[] EnteringBallsDimensions()
  146.     {
  147.         string[] entersBallsDimensions = Console.ReadLine().Split();
  148.         int[] ballsLocation = new int[2];
  149.         for (int i = 0; i < 2; i++)
  150.         {
  151.             ballsLocation[i] = int.Parse(entersBallsDimensions[i]);
  152.         }
  153.         return ballsLocation;
  154.     }
  155.  
  156.     private static string[, ,] EnteringDataForTheCube(string[, ,] cube)
  157.     {
  158.         for (int h = 0; h < cube.GetLength(1); h++)
  159.         {
  160.             string[] lineFragment = Console.ReadLine().Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
  161.  
  162.             for (int d = 0; d < cube.GetLength(2); d++)
  163.             {
  164.                 string[] cubeContent = lineFragment[d].Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
  165.  
  166.                 for (int w = 0; w < cube.GetLength(0); w++)
  167.                 {
  168.                     cube[w, h, d] = cubeContent[w];
  169.                 }
  170.             }
  171.         }
  172.         return cube;
  173.     }
  174.  
  175.     private static int[] EnteringDimensionsForCube()
  176.     {
  177.         string[] data = Console.ReadLine().Split();
  178.         int[] dimensions = new int[3];
  179.  
  180.         for (int i = 0; i < 3; i++)
  181.         {
  182.             dimensions[i] = int.Parse(data[i]);
  183.         }
  184.         return dimensions;
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement