#C11735. Robot Order Simulation

    ID: 41084 Type: Default 1000ms 256MiB

Robot Order Simulation

Robot Order Simulation

You are given two strings that simulate the movement of robots over a series of platforms. The first string represents the robots in their initial order. The second string represents the platform layout, consisting of two possible characters:

  • -: a solid platform step
  • .: a gap where the robots must adjust their positions

The simulation works as follows: for each character in the platform string, if the character is a gap (i.e. .), then all robots move. They move in reverse order (from the last robot to the first) and their position is updated to the current index + 1. After processing the entire platform string, the final order of robots is determined by sorting them in ascending order according to their last updated position. In case of ties, the sorting is done by the natural lexicographical order of the robot identifiers.

Note: The input guarantees that when the robots are given, they are arranged in alphabetical order so that the final order always matches the input order. However, you must implement the simulation exactly as described.

Formally, if we denote the platform string as \( P = P_0P_1\ldots P_{n-1} \), then for each index \( i \) where \( P_i = \texttt{.} \), update the position of every robot \( r \) as:

\[ \text{position}(r) = i + 1 \]

After processing, output the concatenation of the robot identifiers sorted by their positions in ascending order.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a non-empty string representing the robots (e.g. ABC).
  2. The second line contains a non-empty string representing the sequence of platform segments, composed exclusively of '-' and '.' characters (e.g. ---.---).

You can assume that the robot string is given in alphabetical order.

outputFormat

Output to standard output (stdout) a single line string representing the order in which the robots reach the final platform, as computed by the simulation.

## sample
ABC
-------
ABC