P1098 [NOIP 2007 Senior] String Expansion

Description

In the preliminary round’s Junior “read the program and write the result” problem, we once gave an example of string expansion: if the input string contains substrings like `d-h` or `4-8`, we treat them as shorthand. In the output, we replace the hyphen with a sequence of consecutively increasing letters or digits; that is, the two substrings above are output as `defgh` and `45678`. In this problem, we add parameters to make the expansion more flexible. The conventions are as follows: (1) Perform string expansion when the following condition is met: in the input string, there is a hyphen `-`, the characters on both sides are both lowercase letters or both digits, and according to `ASCII` order, the character on the right of the hyphen is strictly greater than the character on the left. (2) Parameter $p_1$: expansion mode. When $p_1=1$, for letter substrings, fill with lowercase letters; when $p_1=2$, for letter substrings, fill with uppercase letters. In both of these cases, the filling method for digit substrings is the same. When $p_1=3$, regardless of whether it is a letter substring or a digit substring, fill with asterisks `*`, using the same number of asterisks as the number of characters that would be filled. (3) Parameter $p_2$: the repetition count of each filling character. $p_2=k$ means the same character is repeated $k$ times consecutively. For example, when $p_2=3$, the substring `d-h` should expand to `deeefffgggh`. The characters on both sides of the hyphen remain unchanged. (4) Parameter $p_3$: whether to reverse the order. $p_3=1$ means keep the original order; $p_3=2$ means output in reverse order. Note that in this case the two endpoint characters are still excluded. For example, when $p_1=1$, $p_2=2$, $p_3=2$, the substring `d-h` should expand to `dggffeeh`. (5) If the character on the right of the hyphen is exactly the successor of the left character, delete only the hyphen; for example, `d-e` should be output as `de`, and `3-4` should be output as `34`. If, according to `ASCII` order, the character on the right of the hyphen is less than or equal to the left character, keep the hyphen in the output; for example, `d-d` should be output as `d-d`, and `3-1` should be output as `3-1`.

Input Format

Two lines. Line $1$: three positive integers separated by spaces, representing $p_1, p_2, p_3$. Line $2$: one string consisting only of digits, lowercase letters, and hyphens `-`. There are no leading or trailing spaces.

Output Format

One line, the expanded string.

Explanation/Hint

$40\%$ of the testdata satisfy: the string length does not exceed $5$. $100\%$ of the testdata satisfy: $1 \le p_1 \le 3$, $1 \le p_2 \le 8$, $1 \le p_3 \le 2$. The string length does not exceed $100$. NOIP 2007 Senior Problem 2. Translated by ChatGPT 5