Witness Redaction Plan

Time limit1sMemory limit128 MB

Summary
Replace every character of each sentence that contains a sensitive word (case-insensitive) with @, keeping the rest of the message unchanged.
Level

Medium4 of 10

Topics
String, Implementation, Simulation
Solved
No attempts yet

Problem

A witness protection program gives crime witnesses new identities to protect them from retaliation by the people they testify against.

Experience shows that many protected witnesses are their own worst enemies: while trying to reach relatives and friends to reassure them that all is well, they give away their new location and identity.

A new pilot allows such contact, but only by email. Program staff first inspect each message and cut out any potentially dangerous sentences, then forward the email from department computers so it cannot be traced back to the witness.

Because the pilot budget was cut, there is not enough money to have people read every message, so an automated solution is needed.

Given a list of sensitive words and a plain-text message, scan the message for any sentence that contains a sensitive word (ignoring letter case). In every such sentence, replace every character (except line terminators) with the character @.

For this problem:

  • A word is a maximal run of consecutive alphanumeric characters. Its boundaries are the start or end of the message and/or any non-alphanumeric character.
  • A sentence is a maximal run of consecutive characters bounded by the start or end of the message, by a paragraph boundary (a line containing zero characters), and/or by one of the punctuation characters ., ?, or !. The punctuation character that ends a sentence belongs to that sentence.

Input

The input contains one or more data sets. Each data set is a word list followed by a message. The end of the input is a line containing only EndOfInput.

A word list contains zero or more words, one per line, left-justified. Each word is at most 40 characters long. The word list ends with a line containing only EndOfList.

The word list is immediately followed by a message. A message contains zero or more lines of text, each at most 80 characters long. The message ends with a line containing only EndOfMsg.

Output

For each data set, print the message exactly as it appears in the input, except that every sentence containing a sensitive word is replaced by @ characters as described above. After each message, print a line containing only four = characters (====).

Examples3

  1. Example 1

    Input
    John
    jane
    Smith
    Jones
    Kansas
    court
    crime
    phone
    555
    EndOfList
    Dear Mom,
    
    I just wanted to let you know that I am alive and well. Jane is
    well also. I’m glad they were able to relocate us. My
    only complaint is that I wish they could have found someplace
    more exciting than Kansas for us to live in! If you really need
    to contact us, you can do so by telephone. The number is
    (757) 555-0478, but don’t tell anyone.
    
    Love,
    the new John Smith
    EndOfMsg
    EndOfInput
    
    Expected output
    Dear Mom,
    
    I just wanted to let you know that I am alive and well.@@@@@@@@
    @@@@@@@@@@ I’m glad they were able to relocate us.@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ If you really need
    to contact us, you can do so by telephone.@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    @@@@@
    @@@@@@@@@@@@@@@@@@
    ====
    
  2. Example 2

    Input
    EndOfList
    Hello world. This is fine!
    EndOfMsg
    EndOfInput
    
    Expected output
    Hello world. This is fine!
    ====
    
  3. Example 3

    Input
    phone
    EndOfList
    Call me on the phone. Use the telephone instead.
    EndOfMsg
    EndOfInput
    
    Expected output
    @@@@@@@@@@@@@@@@@@@@@ Use the telephone instead.
    ====