Advertisement
Guest User

namenum

a guest
Dec 9th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. Name That Number
  2.  
  3. Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the members of their herd by a pleasing name rather than saying, "C'mon, #4734, get along."
  4.  
  5. Help the poor cowhands 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 cow 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"):
  6.  
  7. 2: A,B,C 5: J,K,L 8: T,U,V
  8. 3: D,E,F 6: M,N,O 9: W,X,Y
  9. 4: G,H,I 7: P,R,S
  10.  
  11. Acceptable names for cattle are provided to you in a file named "dict.txt", which contains a list of fewer than 5,000 acceptable cattle names (all letters capitalized). Take a cow's brand number and report which of all the possible words to which that number maps are in the given dictionary which is supplied as dict.txt in the grading environment (and is sorted into ascending order).
  12.  
  13. For instance, the brand number 4734 produces all the following names:
  14.  
  15. GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI
  16. GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI
  17. GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI
  18. HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI
  19. HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI
  20. IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI
  21. ISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI
  22.  
  23. As it happens, the only one of these 81 names that is in the list of valid names is "GREG".
  24.  
  25. Write a program that is given the brand number of a cow and prints all the valid names that can be generated from that brand number or ``NONE'' if there are no valid names. Serial numbers can be as many as a dozen digits long.
  26. PROGRAM NAME: namenum
  27. INPUT FORMAT
  28. A single line with a number from 1 through 12 digits in length.
  29. SAMPLE INPUT (file namenum.in)
  30.  
  31. 4734
  32.  
  33. OUTPUT FORMAT
  34. A list of valid names that can be generated from the input, one per line, in ascending alphabetical order.
  35. SAMPLE OUTPUT (file namenum.out)
  36.  
  37. GREG
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement