#C1797. Domino Push Simulation
Domino Push Simulation
Domino Push Simulation
You are given a string representing a line of dominoes. Each character in the string can be one of the following:
'L'
: A domino that is pushed to the left.'R'
: A domino that is pushed to the right.'.'
: A domino that is initially standing still.
When a domino falls, it applies a force on the neighboring dominoes. The force propagation can be thought of as follows: for each domino i, the net force Fi is computed by summing a rightward force and subtracting a leftward force. In particular, you can view the rightward force as a value that decreases by 1 for each domino away from a domino falling to the right (starting with a large number when a right-falling domino is encountered) and similarly for leftward force. In mathematical notation, if we define the force from right falling dominoes as fRi and from left falling dominoes as fLi, the net force is given by:
where the domino at position i will eventually fall right if Fi > 0, fall left if Fi < 0, or remain standing if Fi = 0.
Your task is to simulate the process and determine the final state of the domino line.
inputFormat
The input consists of a single line containing a string s
which represents the initial state of the dominoes. The string consists only of the characters 'L'
, 'R'
, and '.'
.
outputFormat
Output a single line containing the final state of the dominoes after all possible falls have occurred.
## sample.L.R...LR..L..
LL.RR.LLRRLL..