P

R

O

G

R

A

M

M

I

N

G

 

C

O

M

P

E

T

I

T

I

O

N

 

Name That Cow

Task #9

Novice/Advanced

8 Points

Task Description
Among the large Texas cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department.  The ranch hands don't appreciate the advantage of this filing system and wish to call the members of their herd by a sonorous name rather than saying, "C'mon, #4734, get along."

Help them out by writing a program that will translate the brand serial number of a cow into possible names uniquely associated with that serial number.  Since the ranch hands all have cellular saddle phones these days, use the standard Touch-Tone(R) telephone keypad mapping to get from numbers to letters (except for "Q" and "Z"):

      2: A,B,C          5: J,K,L          8: T,U,V
      3: D,E,F          6: M,N,O          9: W,X,Y
      4: G,H,I          7: P,R,S

Acceptable names for the cows are provided via an input file, which contains a list of fewer than 5,000 acceptable cattle names (first letter capitalized, of course).  Take a cow's brand number and report which of all the possible words to which that number maps are in the given dictionary.

 

For instance, the brand number 4734 produces all the following names:

 

< Isfi Gpeh … Gpeg Gpdi Gpdh Gpei Gpdg … Greg …>

 

As it happens, the only one of these 81 names that is in the list of valid names is "Greg".

 

Write a program that repeatedly asks for the brand number of a cow and prints all the valid names that can be generated from that brand number; print "No matching names found" if no valid words match. Serial numbers can be as many as a 9 digits long. End the program, when the serial number `0' is entered.

Program Input
232
252473
727225
0

Program Output
Possible names for #232 are: Ada
Possible names for #252473 are: Blaise, Claire
Possible names for #727225 are: Pascal