Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Slides
- {
- class Slides
- {
- static void Main()
- {
- string[] readDimensions = Console.ReadLine().Split(' ');
- int width = Int32.Parse(readDimensions[0]);
- int height = Int32.Parse(readDimensions[1]);
- int depth = Int32.Parse(readDimensions[2]);
- // fill cuboid
- string[, ,] cuboid = new string[width, height, depth];
- for (int h = 0; h < height; h++)
- {
- string[] floor = Console.ReadLine().Split('|');
- for (int d = 0; d < depth; d++)
- {
- string[] separateByBrackets = floor[d].Trim().Split(new[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
- for (int w = 0; w < width; w++)
- {
- string cell = separateByBrackets[w];
- cuboid[w, h, d] = cell;
- }
- }
- }
- // get ball position
- readDimensions = Console.ReadLine().Split(' ');
- int ballW = Int32.Parse(readDimensions[0]);
- int ballH = 0;
- int ballD = Int32.Parse(readDimensions[1]);
- int nextBallW = ballW, nextBallH = ballH, nextBallD = ballD;
- bool escaped = true;
- // start the game (drop the ball)
- while (true)
- {
- string instructions = cuboid[nextBallW, nextBallH, nextBallD];
- ballW = nextBallW;
- ballH = nextBallH;
- ballD = nextBallD;
- if (instructions == "B")
- {
- escaped = false;
- break;
- }
- // translate instructions into coordinates
- int[] nextCoordinates = CalculateCoordinates(instructions, ballW, ballH, ballD);
- nextBallW = nextCoordinates[0];
- nextBallH = nextCoordinates[1];
- nextBallD = nextCoordinates[2];
- // check coordinates
- if (instructions[0] != 'T')
- {
- if (ballH == height - 1)
- {
- escaped = true;
- break;
- }
- else
- {
- if ((nextBallW < 0) || (nextBallW > width - 1) || (nextBallD < 0) || (nextBallD > depth - 1))
- {
- escaped = false;
- break;
- }
- }
- }
- }
- // print output
- Console.WriteLine("{0}", escaped ? "Yes" : "No");
- Console.WriteLine("{0} {1} {2}", ballW, ballH, ballD);
- }
- static int[] CalculateCoordinates(string instructions, int ballW, int ballH, int ballD)
- {
- int[] coordinates = new int[3];
- // handle the slide cases
- if (instructions[0] == 'S')
- {
- instructions = instructions.Replace(" ", "");
- }
- // handle SL, SR, SF, SB
- if ((instructions[0] == 'S') && (instructions.Length == 2))
- {
- // SL, SR, SF, SB
- coordinates[1] = ballH + 1;
- switch (instructions[1])
- {
- case 'L':
- coordinates[0] = ballW - 1;
- coordinates[2] = ballD;
- break;
- case 'R':
- coordinates[0] = ballW + 1;
- coordinates[2] = ballD;
- break;
- case 'F':
- coordinates[0] = ballW;
- coordinates[2] = ballD - 1;
- break;
- case 'B':
- coordinates[0] = ballW;
- coordinates[2] = ballD + 1;
- break;
- }
- }
- // handle SFL, SFR, SBL, SBR
- else if ((instructions[0] == 'S') && (instructions.Length == 3))
- {
- coordinates[1] = ballH + 1;
- switch (instructions[1])
- {
- case 'F':
- coordinates[2] = ballD - 1;
- if (instructions[2] == 'L')
- {
- coordinates[0] = ballW - 1;
- }
- else if (instructions[2] == 'R')
- {
- coordinates[0] = ballW + 1;
- }
- break;
- case 'B':
- coordinates[2] = ballD + 1;
- if (instructions[2] == 'L')
- {
- coordinates[0] = ballW - 1;
- }
- else if (instructions[2] == 'R')
- {
- coordinates[0] = ballW + 1;
- }
- break;
- }
- }
- // handle the teleport T 1 1
- else if (instructions[0] == 'T')
- {
- int[] instructionsTeleport = instructions.Substring(2).Split(' ').Select(x => Int32.Parse(x)).ToArray();
- coordinates[0] = instructionsTeleport[0];
- coordinates[1] = ballH;
- coordinates[2] = instructionsTeleport[1];
- }
- // handle empty cell
- else if (instructions[0] == 'E')
- {
- coordinates[0] = ballW;
- coordinates[1] = ballH + 1;
- coordinates[2] = ballD;
- }
- return coordinates;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement