Injured Shoulder
InterviewTime limit5sMemory limit1024 MB
Given a dictionary and typed words, print 1 if a word is in the dictionary, 2 if it is two dictionary words joined without a space, and 0 otherwise.
Problem
Dr. Orooji injured his right shoulder a few months ago and could type with only one hand for a while. For some reason, Dr. O often missed the space character (blank), so two words ended up next to each other without a space, and the spell-checker flagged them.
Given the words in a dictionary and a word Dr. O has typed, determine the status of the typed word.
Input
The first line contains an integer (), the number of words in the dictionary. Each of the next lines contains one dictionary word. Each word starts in column 1, contains at least one and at most 20 lowercase letters, and no other characters. The dictionary words are unique.
The next line contains an integer (), the number of words Dr. O has typed. Each of the next lines contains one typed word. Each typed word starts in column 1, contains at least one and at most 40 lowercase letters, and no other characters.
Output
For each typed word, print one line:
- 1: if the typed word is in the dictionary.
- 2: if the typed word is a concatenation of two dictionary words, meaning Dr. O left out the space character.
- 0: otherwise.
If a typed word is in the dictionary and is also a concatenation of two dictionary words, the output is 1.