#P1098. [NOIP 2007 提高组] 字符串的展开

[NOIP 2007 提高组] 字符串的展开

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 p1p_1: expansion mode. When p1=1p_1=1, for letter substrings, fill with lowercase letters; when p1=2p_1=2, for letter substrings, fill with uppercase letters. In both of these cases, the filling method for digit substrings is the same. When p1=3p_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 p2p_2: the repetition count of each filling character. p2=kp_2=k means the same character is repeated kk times consecutively. For example, when p2=3p_2=3, the substring d-h should expand to deeefffgggh. The characters on both sides of the hyphen remain unchanged.

(4) Parameter p3p_3: whether to reverse the order. p3=1p_3=1 means keep the original order; p3=2p_3=2 means output in reverse order. Note that in this case the two endpoint characters are still excluded. For example, when p1=1p_1=1, p2=2p_2=2, p3=2p_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 11: three positive integers separated by spaces, representing p1,p2,p3p_1, p_2, p_3.

Line 22: one string consisting only of digits, lowercase letters, and hyphens -. There are no leading or trailing spaces.

Output Format

One line, the expanded string.

1 2 1
abcs-w1234-9s-4zz
abcsttuuvvw1234556677889s-4zz
2 3 2
a-d-d
aCCCBBBd-d

Hint

40%40\% of the testdata satisfy: the string length does not exceed 55.

100%100\% of the testdata satisfy: 1p131 \le p_1 \le 3, 1p281 \le p_2 \le 8, 1p321 \le p_3 \le 2. The string length does not exceed 100100.

NOIP 2007 Senior Problem 2.

Translated by ChatGPT 5