given dictionary</a> which is supplied as dict.txt in the grading environment (and is sorted into ascending order). </p>
For instance, the brand number 4734 produces all the following names: </p>
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 </pre>
As it happens, the only one of these 81 names that is in the list of valid names is "GREG". </p>
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. </p>
PROGRAM NAME: namenum</h3>
INPUT FORMAT</h3> A single line with a number from 1 through 12 digits in length.
SAMPLE INPUT (file namenum.in) </h3>
4734 </pre>
OUTPUT FORMAT</h3> A list of valid names that can be generated from the input, one per line, in ascending alphabetical order.
SAMPLE OUTPUT (file namenum.out)</h3>
GREG /*
ID: hippo he
LANG: C
TASK:namenum
*/
#include
#include
#include
typedef struct code
{
int num;
char a[3];
}code,*pcode;
void input(char *src)
{
FILE*fp=fopen("namenum.in","r");
fscanf(fp,"%s",src);
fclose(fp);
}
char* transcode(FILE**fp,pcode glob,char (*des)[13],char*src)
{
char *buf,*nu;
int i,j,k,m=1,flag=0;
nu=(char*)malloc(13*sizeof(char));
buf=(char*)malloc(13*sizeof(char));
i=fscanf(*fp,"%s",buf);
if(i<=0) return NULL;
else
{
for(i=0;i<13;i++)
{
if(buf[i])
{
for(j=0;j<8;j++)
{
flag=0;
for(k=0;k<3;k++)
{
if(buf[i]==glob[j].a[k])
{
nu[i]=glob[j].num+'0';
flag=1;
break;
}
}
if(flag==1)break;
}
if(flag==0) return src;
}
}
}
if(!strcmp(nu,src))
return buf;
else return src;
}
void ouput(char (*des)[13],int m)
{
FILE *fp=fopen("namenum.out","w");
int i;
if(m==0)
fprintf(fp,"NONEn",&m);
else
{
for(i=0;i fprintf(fp,"%sn",des[i]);
}
fclose(fp);
}
int main (int argc, char const* argv[])
{
int i,m=0,j=0;
code glob[8]={
{2,'A','B','C'},
{3,'D','E','F'},
{4,'G','H','I'},
{5,'J','K','L'},
{6,'M','N','O'},
{7,'P','R','S'},
{8,'T','U','V'},
{9,'W','X','Y'},
};
char src[13],*buf,des[200][13];
FILE *fp=fopen("dict.txt","r");
input(src);
for(i=0;;i++)
{
buf=transcode(&fp,glob,des,src);
if(buf==NULL)
{
break;
}
else if(buf==src);
else
{
strcpy(des[j++],buf);
}
}
ouput(des,j);
fclose(fp);
return 0;
}
</pre> </div>