10381 - Pushing box   

Description

The game is played on a board of squares, where each square is a floor, which is marked as ‘ ‘, or a wall, which is marked as ‘#’. Some floor squares contain boxes which are marked as ‘B’, and some floor squares are marked as storage locations, which is marked as ‘S’.

The player, which is marked as ‘P’, is confined to the board, and may move horizontally or vertically onto empty squares (never through walls or boxes). The player can also move into a box, which pushes it into the square beyond. Boxes may not be pushed into other boxes or walls, and they cannot be pulled. The puzzle is solved when all boxes are at storage locations.
 
We will first give a map which contains the positions of walls and storage locations. The size of the map is 10 x 10. And we will give you the position of the player. We will use U, D, R, and L, represent up, down, right, and left. The following M instructions will use those words to point out where the player should move. Finally, we have to print out the map and show the number of boxes which are at the storage locations.
 
[Note] If the box is on the storage location. You have to print B instead of S. If the player is on the storage location. You have to print P instead of S.

Input

Read the 10 x 10 map first. (The left-up position is (0, 0) )

Read the position of the player.

Read an integer M which indicates the number of direction instructions.

The next M lines contain the direction instructions.

Output

The number of boxes which are at the storage locations.

The 10 x 10 map.

Sample Input  Download

Sample Output  Download

Tags




Discuss