Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Slides
- {
- public static string[, ,] cube;
- public static int widthOfCube, heightOfCube, depthOfCube, ballsWidth, ballsHeight, ballsDepth;
- public static int[] dimensionsOfTheCube;
- static void Main()
- {
- dimensionsOfTheCube = EnteringDimensionsForCube();
- widthOfCube = dimensionsOfTheCube[0];
- heightOfCube = dimensionsOfTheCube[1];
- depthOfCube = dimensionsOfTheCube[2];
- cube = new string[widthOfCube, heightOfCube, depthOfCube];
- cube = EnteringDataForTheCube(cube);
- int[] ballsLocation = EnteringBallsDimensions();
- ballsWidth = ballsLocation[0];
- ballsDepth = ballsLocation[1];
- ballsHeight = 0;
- while (true)
- {
- string currentCell = cube[ballsWidth, ballsHeight, ballsDepth];
- string[] commandAndDirection = currentCell.Split();
- string command = commandAndDirection[0];
- switch (command)
- {
- case "S":
- SlidingTheBall(commandAndDirection[1]);
- break;
- case "T":
- ballsWidth = int.Parse(commandAndDirection[1]);
- ballsDepth = int.Parse(commandAndDirection[2]);
- break;
- case "E":
- if (ballsHeight == dimensionsOfTheCube[1] - 1)
- {
- PrintintMessage();
- return;
- }
- else
- {
- ballsHeight++;
- }
- break;
- case "B":
- PrintintMessage();
- return;
- default: throw new ArgumentException();
- }
- }
- }
- private static void PrintintMessage()
- {
- string currentCell = cube[ballsWidth, ballsHeight, ballsDepth];
- if ((currentCell == "B") || (ballsHeight != (dimensionsOfTheCube[1] - 1)))
- {
- Console.WriteLine("No");
- }
- else
- {
- Console.WriteLine("Yes");
- }
- Console.WriteLine("{0} {1} {2}", ballsWidth, ballsHeight, ballsDepth);
- }
- private static void SlidingTheBall(string direction)
- {
- switch (direction)
- {
- case "L":
- ballsWidth--;
- ballsHeight++;
- break;
- case "R":
- ballsWidth++;
- ballsHeight++;
- break;
- case "F":
- ballsDepth--;
- ballsHeight++;
- break;
- case "B":
- ballsDepth++;
- ballsHeight++;
- break;
- case "FL":
- ballsDepth--;
- ballsWidth--;
- ballsHeight++;
- break;
- case "FR":
- ballsDepth--;
- ballsWidth++;
- ballsHeight++;
- break;
- case "BL":
- ballsDepth++;
- ballsWidth--;
- ballsHeight++;
- break;
- case "BR":
- ballsDepth++;
- ballsWidth++;
- ballsHeight++;
- break;
- default: throw new ArgumentException();
- }
- if (!IsPassable())
- {
- Console.WriteLine("No");
- Console.WriteLine("{0} {1} {2}", ballsWidth, ballsHeight, ballsDepth);
- Environment.Exit(0);
- }
- }
- private static bool IsPassable()
- {
- if (ballsWidth >= 0 &&
- ballsHeight >= 0 &&
- ballsDepth >= 0 &&
- ballsWidth < dimensionsOfTheCube[0] &&
- ballsHeight < dimensionsOfTheCube[1] &&
- ballsDepth < dimensionsOfTheCube[2])
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private static int[] EnteringBallsDimensions()
- {
- string[] entersBallsDimensions = Console.ReadLine().Split();
- int[] ballsLocation = new int[2];
- for (int i = 0; i < 2; i++)
- {
- ballsLocation[i] = int.Parse(entersBallsDimensions[i]);
- }
- return ballsLocation;
- }
- private static string[, ,] EnteringDataForTheCube(string[, ,] cube)
- {
- for (int h = 0; h < cube.GetLength(1); h++)
- {
- string[] lineFragment = Console.ReadLine().Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
- for (int d = 0; d < cube.GetLength(2); d++)
- {
- string[] cubeContent = lineFragment[d].Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
- for (int w = 0; w < cube.GetLength(0); w++)
- {
- cube[w, h, d] = cubeContent[w];
- }
- }
- }
- return cube;
- }
- private static int[] EnteringDimensionsForCube()
- {
- string[] data = Console.ReadLine().Split();
- int[] dimensions = new int[3];
- for (int i = 0; i < 3; i++)
- {
- dimensions[i] = int.Parse(data[i]);
- }
- return dimensions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement