Advertisement
stoianpp

slide

Jan 4th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 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. class Slides
  8. {
  9.     static void Main()
  10.     {
  11.         string[] measures = Console.ReadLine().Split(' ');
  12.         int w = int.Parse(measures[0]);
  13.         int h = int.Parse(measures[1]);
  14.         int d = int.Parse(measures[2]);
  15.         string[,,] cube = new string[w,h,d];
  16.         ReadingAndInput(cube, h);
  17.         string[] dropPoint = Console.ReadLine().Split(' ');
  18.         int[] position = {int.Parse(dropPoint[0]),0,int.Parse(dropPoint[1])};
  19.         Moving(position,cube);
  20.     }
  21.  
  22.     static void Moving(int[] position,string[,,] cube)
  23.     {
  24.         while (true)
  25.         {
  26.             bool yes = false;
  27.             int[] currPosition = new int[3];
  28.             Array.Copy(position, currPosition,3);
  29.             char move = cube[position[0], position[1], position[2]][1];
  30.            
  31.             switch(move)
  32.             {
  33.                 case 'S': Slide(cube[position[0], position[1], position[2]],position); break;
  34.                 case 'T': Teleport(cube[position[0], position[1], position[2]], position); break;
  35.                 case 'E': position[1]++;break;
  36.                 case 'B': Printing(currPosition,yes);break;
  37.             }
  38.             if (move == 'B') break;
  39.             if (position[0]<0 || position[0]>=cube.GetLength(0) || (position[1]==cube.GetLength(1)&&move=='S')
  40.                 || position[2] < 0 || position[2] >= cube.GetLength(2) || position[1] > cube.GetLength(1))
  41.             {
  42.                 if (position[1] >= cube.GetLength(1)) yes = true;
  43.                 Printing(currPosition,yes);
  44.                 break;
  45.             }
  46.         }
  47.     }
  48.  
  49.     static void Printing(int[] endPosition,bool end)
  50.     {
  51.         if (end)
  52.         {
  53.             Console.WriteLine("Yes");
  54.             Console.WriteLine(string.Join(" ",endPosition));
  55.         }
  56.         else
  57.         {
  58.             Console.WriteLine("No");
  59.             Console.WriteLine(string.Join(" ",endPosition));
  60.         }
  61.     }
  62.  
  63.     static void Teleport(string move, int[] position)
  64.     {
  65.         position[0] = int.Parse(move[3].ToString());
  66.         position[2] = int.Parse(move[5].ToString());
  67.     }
  68.  
  69.     static void Slide(string move,int[] position)
  70.     {
  71.         for (int i = 3; i <= 4; i++)
  72.         {
  73.             switch (move[i])
  74.             {
  75.                 case 'L': position[0]--; break;
  76.                 case 'R': position[0]++; break;
  77.                 case 'B': position[2]++; break;
  78.                 case 'F': position[2]--; break;
  79.             }
  80.         }
  81.         position[1]++;
  82.     }
  83.  
  84.     static void ReadingAndInput(string[,,] cube, int hh)
  85.     {
  86.         for (int h = 0; h < hh; h++)
  87.         {
  88.             string inputRow = Console.ReadLine();
  89.             int openBracket = 0;
  90.             int closeBracket = inputRow.IndexOf(")");
  91.             for (int d = 0; d < cube.GetLength(2); d++)
  92.             {
  93.                 for (int w = 0; w < cube.GetLength(0); w++)
  94.                 {
  95.                     cube[w,h,d] = inputRow.Substring(openBracket,closeBracket+1-openBracket);
  96.                     openBracket = inputRow.IndexOf("(", closeBracket);
  97.                     if (openBracket < 0) break;
  98.                     closeBracket = inputRow.IndexOf(")",openBracket);
  99.                 }
  100.             }
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement