Among the large Wisconsin cattle ranchers, it is customary to brandcows with serial numbers to please the Accounting Department. The cowhands don't appreciate the advantage of this filing system, though, andwish to call the members of their herd by a pleasing name rather thansaying, "C'mon, #4734, get along."
Help the poor cowhands out by writing a program that will translatethe brand serial number of a cow into possible names uniquely associatedwith that serial number. Since the cow hands all have cellular saddlephones these days, use the standard Touch-Tone(R) telephone keypadmapping 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 cattle are provided to you in a file named"dict.txt", which contains a list of fewer than 5,000acceptable cattle names (all letters capitalized). Take a cow'sbrand number and report which of all the possible words to whichthat number maps are in the givendictionary which is supplied as dict.txt in the gradingenvironment (and is sorted into ascending order).
For instance, the brand number 4734 produces all the following names:
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
As it happens, the only one of these 81 names that is in the listof valid names is "GREG".
Write a program that is given the brand number of a cow andprints all the valid names that can be generated from that brandnumber or ``NONE'' if there are no valid names. Serial numbers canbe as many as a dozen digits long.
PROGRAM NAME: namenum
INPUT FORMAT
A single line with a number from 1 through 12 digits in length.SAMPLE INPUT (file namenum.in)
4734
OUTPUT FORMAT
A list of valid names that can be generated from the input, one perline, in ascending alphabetical order.SAMPLE OUTPUT (file namenum.out)
GREG
CODE:
/*
ID: sotifis3
LANG: C++
TASK: namenum
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const char code[26]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','0','7','7','8','8','8','9','9','9','0'};
char a[13],b[13];
int main()
{
freopen("namenum.in","r",stdin);
freopen("namenum.out","w",stdout);
freopen("dict.txt","r",stderr);
bool flag=1;
cin>>a;
while (fscanf(stderr,"%s",b)!=EOF)
{
bool flg=1;
if (strlen(a)!=strlen(b)) continue;
for (int i=0;b[i];i++) flg=flg&&(code[b[i]-'A']==a[i]);
if (flg) flag=0,cout<<b<<endl;
}
if (flag) cout<<"NONE"<<endl;
return 0;
}