Advertisement
Tedski

Untitled

Dec 27th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 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 Ball
  8. {
  9. private int width;
  10. private int depth;
  11. private int height = 0;
  12.  
  13. public Ball(int width, int depth)
  14. {
  15. this.width = width;
  16. this.depth = depth;
  17. }
  18.  
  19. public int Width
  20. {
  21. get { return this.width; }
  22. set { this.width = value; }
  23. }
  24. public int Depth
  25. {
  26. get { return this.depth; }
  27. set { this.depth = value; }
  28. }
  29. public int Height
  30. {
  31. get { return this.height; }
  32. set { this.height = value; }
  33. }
  34. }
  35.  
  36. class Program
  37. {
  38. static string[, ,] cube;
  39. static int cubeWidth, cubeHeight, cubeDepth;
  40. static int tempBallWidth, tempBallHeight, tempBallDepth;
  41.  
  42. static void ReadInput()
  43. {
  44. string[] input = Console.ReadLine().Split(' ');
  45. cubeWidth = int.Parse(input[0]);
  46. cubeHeight = int.Parse(input[1]);
  47. cubeDepth = int.Parse(input[2]);
  48. cube = new string[cubeWidth, cubeHeight, cubeDepth];
  49.  
  50. for (int h = 0; h < cubeHeight; h++)
  51. {
  52. string[] lineSplit = Console.ReadLine().Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
  53. for (int d = 0; d < cubeDepth; d++)
  54. {
  55. string[] sequenceSplit = lineSplit[d].Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
  56. for (int w = 0; w < cubeWidth; w++)
  57. {
  58. cube[w, h, d] = sequenceSplit[w];
  59. }
  60. }
  61. }
  62.  
  63. }
  64.  
  65. static void CheckBallCoordinates(Ball ball)
  66. {
  67. int[] ballCoordinates = { ball.Width, ball.Height, ball.Depth };
  68. bool result = false;
  69. for (int i = 0; i < ballCoordinates.Length; i++)
  70. {
  71. if (ballCoordinates[i] == -1)
  72. {
  73. result = true;
  74. break;
  75. }
  76. if (ballCoordinates[i] >= cubeWidth || ballCoordinates[i] >= cubeHeight || ballCoordinates[i] >= cubeDepth)
  77. {
  78. result = true;
  79. break;
  80. }
  81. }
  82. if (result)
  83. {
  84. if (ball.Height >= cubeHeight)
  85. {
  86. Console.WriteLine("Yes\n{0} {1} {2}", tempBallWidth, tempBallHeight, tempBallDepth);
  87. Environment.Exit(0);
  88. }
  89. else
  90. {
  91. Console.WriteLine("No\n{0} {1} {2}", tempBallWidth, tempBallHeight, tempBallDepth);
  92. Environment.Exit(0);
  93. }
  94. }
  95.  
  96.  
  97. }
  98.  
  99. static void Main()
  100. {
  101. ReadInput();
  102. string[] ballInput = Console.ReadLine().Split(' ');
  103. Ball ball = new Ball(int.Parse(ballInput[0]), int.Parse(ballInput[1]));
  104.  
  105. while (true)
  106. {
  107. string[] currentPosition = cube[ball.Width, ball.Height, ball.Depth].Split(' ');
  108. //Keeps old coordinates of the ball
  109. tempBallWidth = ball.Width;
  110. tempBallHeight = ball.Height;
  111. tempBallDepth = ball.Depth;
  112. //
  113. string currentCommand = currentPosition[0];
  114. if (currentCommand == "S")
  115. {
  116. ball.Height++;
  117. switch (currentPosition[1])
  118. {
  119. case "L":
  120. ball.Width--; CheckBallCoordinates(ball); break;
  121. case "R":
  122. ball.Width++; CheckBallCoordinates(ball); break;
  123. case "F":
  124. ball.Depth--; CheckBallCoordinates(ball); break;
  125. case "B":
  126. ball.Depth++; CheckBallCoordinates(ball); break;
  127. case "FL":
  128. ball.Depth--; ball.Width--; CheckBallCoordinates(ball); break;
  129. case "FR":
  130. ball.Depth--; ball.Width++; CheckBallCoordinates(ball); break;
  131. case "BL":
  132. ball.Depth++; ball.Width--; CheckBallCoordinates(ball); break;
  133. case "BR":
  134. ball.Depth++; ball.Width++; CheckBallCoordinates(ball); break;
  135. default:
  136. break;
  137. }
  138. }
  139. else if (currentCommand == "T")
  140. {
  141. ball.Width = int.Parse(currentPosition[1]);
  142. ball.Depth = int.Parse(currentPosition[2]);
  143. CheckBallCoordinates(ball);
  144. }
  145. else if (currentCommand == "E")
  146. {
  147. ball.Height++;
  148. CheckBallCoordinates(ball);
  149. }
  150. else if (currentCommand == "B")
  151. {
  152. Console.WriteLine("No\n{0} {1} {2}", ball.Width, ball.Height, ball.Depth);
  153. Environment.Exit(0);
  154. }
  155. }
  156. }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement