14440 - Shoot the ball   

Description

In this question, we want to shoot the ball from a certain coordinate in D direction and determine the final position of the ball

The ball will go in the given direction until it leaves the map or collides with a wall. In the latter case, the ball will change its direction based on its original direction and the wall's arrangement, namely:

  • Going Left:
    • Meet /: Change direction to Down
    • Meet \: Change direction to Up
  • Going Right:
    • Meet /: Change direction to Up
    • Meet \: Change direction to Down
  • Going Up:
    • Meet /: Change direction to Right
    • Meet \: Change direction to Left
  • Going Down:
    • Meet /: Change direction to Left
    • Meet \: Change direction to Right

For example in the sample input:

However, the ball can also stuck in the map forever.

Input

The first line will be H, W, and D, representing the Height, Width of the map, and Direction

The next line will be HxW map, containing either '/', '\', '.', and 'S'

  • / representing a wall from bottom left grid to top right grid
  • \ representing a wall from top left grid to bottom right grid
  • . representing an empty space
  • S representing the starting point of the ball. It is guaranteed that there will be exactly one S in all test cases.

1 <= H, W <= 100

D is a string, the possibilites are "Left", "Right", "Up", and "Down"

Output

Print the last coordinate before the ball leaves the border map (outside of the array) with format row and column, separated by a space.

If it is not possible to go out from the array, print "Stuck QQ"

Don't forget the new line character after the end of the output.

Sample Input  Download

Sample Output  Download

Tags




Discuss