Programming Problem #35
"String Matching"

Your job is to implement a simple string pattern-matching facility, like the ones available in many text editors. For this problem, a pattern consists of one or more lowercase letters and wildcards. The "?" wildcard matches any letter, and the "*" wildcard matches any sequence of zero or more letters.

The input consists of one or more pattern groups. A line beginning with a colon starts a pattern group. If the second character is also a colon it signals the end of the input. Otherwise the remainder of the line contains the pattern, and subsequent lines (up until the next pattern group) are nonempty strings to be matched against the pattern. Strings to be matched will contain only lowercase letters. The output must be identical to the input, except that at the end of each string you must append either " [Y]" or " [N]" depending on whether the string matched its pattern.

Input must be read from the file "prob35.in", and output must be written to the file "prob35.out". All output to the screen will be ignored.


Example Input

<BOF>
:a*b??c*d
abcd
abobcd
abigbrickdumptruck
:frog
horse
abullfrogfarm
frog
:*hi*?*ho?
hiho
shiptoshore
hiphop
:*
doesthismatch
::
<EOF>

Example Output

:a*b??c*d
abcd [N]
abobcd [Y]
abigbrickdumptruck [N]
:frog
horse [N]
abullfrogfarm [N]
frog [Y]
:*hi*?*ho?
hiho [N]
shiptoshore [N]
hiphop [Y]
:*
doesthismatch [Y]
::

Dr. Eric Shade