MojtabaMahdiDooz
SRM 767 · 2019-09-17 · by minimario
Problem Statement
Mahdi is learning the game Dooz by observing Mojtaba who's playing it.
The game is played on a 1 times n board. Mojtaba has several marbles: exactly one white marble (denoted 'W'), and zero or more black ones (denoted 'B'). At the beginning of the game, the white marble is placed onto the leftmost cell of the board, and the black marbles are placed onto other cells, one per cell. Some cells may remain empty (denoted '-').
Mojtaba then moves the white marble. In each move he can do one of two things:
- If the cell immediately to the right of the white marble is empty, Mojtaba moves the white marble one cell to the right.
- If the cell immediately to the right of the white marble contains a black marble and the next cell after that is empty, Mojtaba jumps the white marble over the black marble, which moves the white marble two cells to the right.
Given the initial state of the game, print the final state of the game.
Constraints
- Length of board will be between 1 and 50, inclusive.
- Character 0 of board will be 'W'.
- Each other character of board will be '-' or 'B'.
"W----" Returns: "----W"
As there are no obstacles, Mojtaba can move the white marble all the way to the right.
"WB-B-B-" Returns: "-B-B-BW"
On this board Mojtaba will make three moves of the second type (jumps over a single black marble).
"W--BB---" Returns: "--WBB---"
We cannot jump over more than one black marble, so the best we can do is to move the white marble two steps to the right.
"W" Returns: "W"
"W-B--B---BB-" Returns: "--B--B--WBB-"
Submissions are judged against all 16 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MojtabaMahdiDooz with a public method string play(string board) · 16 test cases · 2 s / 256 MB per case