#P3864. [USACO1.2] 命名那个数字 Name That Number
[USACO1.2] 命名那个数字 Name That Number
Description
Among dairy farmers in Wisconsin, it is customary for the accounting department to brand cows with consecutive numbers. The cows themselves do not find this system convenient; they prefer to call their companions by their favorite names rather than with phrases like "C'mon, #4364, be friendly." Please write a program to help the poor cowhands translate a cow's brand number into a possible name. Since cows now all have cell phones, you can convert digits to letters according to the table below.
| Digit | Letters |
|---|---|
| A,B,C | |
| D,E,F | |
| G,H,I | |
| J,K,L | |
| M,N,O | |
| P,R,S | |
| T,U,V | |
| W,X,Y |
Note that the letters Q and Z are not present.
The set of acceptable cow names is stored in a file called "dict.txt", which contains a sequence of fewer than (specifically, ) acceptable names. All names are uppercase and already sorted in lexicographical order. Read the cow's number and return those names that can be translated from the number and appear in the dictionary. For example, among the names generated by the number , only "GREG" is valid (i.e., present in the dictionary).
Write a program to print all valid names for the given number. If there are none, output NONE.
Input Format
The first line contains a number of length to .
The following lines (until EOF), one per line, each contain a string representing an acceptable name.
Output Format
Output a deduplicated list of valid names in lexicographical order, one name per line. If there are no valid names, output NONE.
4734
NMSL
GREG
LSDC
....(太多了不写了)
GREG
Hint
All combinations producible from are as follows:
GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI ISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI
Translated by ChatGPT 5
京公网安备 11011102002149号