Spelling Be

Interview

Time limit1sMemory limit128 MB

Summary
Read a dictionary and several emails, then report for each email whether all its words are known and list the unknown words in order.
Level

Easy3 of 10

Topics
Hash map, String, Implementation, Simulation
Solved
No attempts yet

Problem

Your company has a simple requirement: every document should be spell-checked before it is sent to a customer. Word-processing documents are easy to spell-check, but employees do not always run a spell-check on the email messages they send. To fix this, you will write a program that checks each outgoing email. It spell-checks every message, and if it finds any spelling errors, the message is returned to the sender for correction.

To try out your program, you use an online dictionary together with some sample emails you have collected.

Input

The input has two parts: the dictionary and the emails.

The first line contains the number of words in the dictionary. Each of the following lines contains one dictionary word. A word has no whitespace before, after, or inside it, but it may contain apostrophes or hyphens, which count as part of the word (so bobs and bob's are different words). There are no duplicate words, and all words are lowercase.

The emails come after the dictionary. The first line of this part contains the number of emails. Each email has already been preprocessed into one word per line, with no punctuation other than apostrophes and hyphens, no whitespace, and all words in lowercase. The end of each email is marked by a line containing only -1. Every email has at least one word.

Output

For each email, print one of the following.

If every word is in the dictionary:

Email X is spelled correctly.

Otherwise:

Email X is not spelled correctly.

followed by every unknown word, one per line, in the order they appear in the email. If an unknown word appears several times, print it once for each occurrence.

Here X is the email number, starting at 1 and increasing by one for each email. Do not print blank lines between emails. After the output for the last email, print a line containing End of Output.

Examples3

  1. Example 1

    Input
    6
    alice
    am
    bitterly
    i
    leaving
    you
    1
    dear
    bob
    i
    am
    leaving
    you
    bitterly
    alice
    -1
    
    Expected output
    Email 1 is not spelled correctly.
    dear
    bob
    End of Output
    
  2. Example 2

    Input
    2
    hello
    world
    1
    hello
    world
    -1
    
    Expected output
    Email 1 is spelled correctly.
    End of Output
    
  3. Example 3

    Input
    3
    a
    b
    c
    2
    a
    b
    c
    -1
    a
    x
    c
    y
    -1
    
    Expected output
    Email 1 is spelled correctly.
    Email 2 is not spelled correctly.
    x
    y
    End of Output