#icpc2014springh. [icpc2014spring_h]RLE Replacement
[icpc2014spring_h]RLE Replacement
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 12px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often appear repeatedly in ICPC programs. Thus, programmers in JAG Kingdom prefer to compress ICPC programs by Run Length Encoding in order to manage very large-scale ICPC programs.
Run Length Encoding (RLE) is a string compression method such that each maximal sequence of the same letters is encoded by a pair of the letter and the length. For example, the string "RRRRLEEE" is represented as "R4L1E3" in RLE.
Now, you manage many ICPC programs encoded by RLE. You are developing an editor for ICPC programs encoded by RLE, and now you would like to implement a replacement function. Given three strings , , and that are encoded by RLE, your task is to implement a function replacing the first occurrence of the substring in with , and outputting the edited string encoded by RLE. If does not occur in , you must output encoded by RLE without changes.
Input
The input consists of three lines.
The lines represent strings , , and that are encoded by RLE, respectively. Each of the lines has the following format:
\$
Each () is an uppercase English letter (A
-Z
) and (, ) is an integer which represents the length of the repetition of . The number of the pairs of a letter and an integer satisfies . A terminal symbol $
indicates the end of a string encoded by RLE. The letters and the integers are separated by a single space. It is guaranteed that holds for any .
Output
Replace the first occurrence of the substring in with if occurs in , and output the string encoded by RLE. The output must have the following format:
\$
Here, for and for must hold.