A Tale from the Dark Side of the Moon
Time limit1sMemory limit128 MB
Reimplement a lost text filter that applies four ordered string rules per line, including conditional ei to ie and dd to p replacements, stopping at a line reading EOF.
- Level
Medium4 of 10
- Topics
- String, Implementation, Simulation, String matching
- Solved
- No attempts yet
Problem
The source code of an old program is gone. All that remains is people's testimony about what it does, and you must reimplement it exactly.
The program reads ordinary text — the kind you might find in an English dictionary — one line at a time, transforms each line by the rules below, and prints the result. Apply the rules to each line in this exact order:
- Replace every pair of adjacent lowercase
ds (dd) with a singlep. (Three or more consecutiveds never occur.) - Replace every
eiwithie, except when theeiimmediately follows the letterc(cei), in which case it stays. - Replace every
pinkwithfloyd. - Delete every character that is neither a lowercase English letter (
a–z) nor a whitespace character. Whitespace is kept exactly as it appears in the input.
Each rule is evaluated on the string produced by the previous steps, and deletion (rule 4) happens last. So the adjacency required by rules 1–3 is judged on the original input. For example, d123d is not turned into p because its two ds are not adjacent — only the digits are removed, leaving dd. In contrast, the dd in 123dd is adjacent, so it becomes p.
The vv-to-m behavior from the original story was just a printer glitch, not a feature of the program. Do not apply it.
Reading stops at a line that is exactly EOF; that line and everything after it are neither processed nor printed.
Input
Several lines of text. Each line is fewer than 80 characters wide. The input ends with a line containing only EOF.
Output
For each line before the EOF line, print the result of applying the rules above in order, one line per input line. Whitespace is preserved exactly as it appears in the input.