A Tale from the Dark Side of the Moon

Time limit1sMemory limit128 MB

Summary
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:

  1. Replace every pair of adjacent lowercase ds (dd) with a single p. (Three or more consecutive ds never occur.)
  2. Replace every ei with ie, except when the ei immediately follows the letter c (cei), in which case it stays.
  3. Replace every pink with floyd.
  4. 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.

Examples1

  1. Example 1

    Input
    unpinked is an 8 letter word. Honest! 
    vv is ok, d123d is ok, 123dd is not 
    i received mail from        liechtenstein
     ..  ...adding means to imitat.#$!%%$e 
    EOF
    
    Expected output
    unfloyded is an  letter word onest 
    vv is ok dd is ok p is not 
    i received mail from        liechtenstien
       aping means to imitate