USACO Section 1.2 : Name That Number
# include <stdio.h>
# include <string.h>
char check(char x)
{
switch(x)
{
case 'A': return '2';
case 'B': return '2';
case 'C': return '2';
case 'D': return '3';
case 'E': return '3';
case 'F': return '3';
case 'G': return '4';
case 'H': return '4';
case 'I': return '4';
case 'J': return '5';
case 'K': return '5';
case 'L': return '5';
case 'M': return '6';
case 'N': return '6';
case 'O': return '6';
case 'P': return '7';
case 'R': return '7';
case 'S': return '7';
case 'T': return '8';
case 'U': return '8';
case 'V': return '8';
case 'W': return '9';
case 'X': return '9';
case 'Y': return '9';
}
}
main ()
{
FILE *in=fopen ("namenum.in","r");
FILE *out=fopen("namenum.out","w");
FILE *dic=fopen("dict.txt","r");
char name[5000][15],fin[15],checkit[15];
int i,j,t=0;
fscanf (in,"%s",fin);
for (i=0;!feof(dic);i++)
{
memset(checkit,'\0',sizeof(checkit));
fscanf (dic,"%s",name[i]);
for (j=0;name[i][j]!='\0';j++)
checkit[j]=check(name[i][j]);
if (strcmp(fin,checkit)==0)
{
fprintf (out,"%s\n",name[i]);
t++;
}
}
if (t==0)
fprintf (out,"NONE\n");
fclose(in);
fclose(out);
fclose(dic);
exit(0);
}
# include <string.h>
char check(char x)
{
switch(x)
{
case 'A': return '2';
case 'B': return '2';
case 'C': return '2';
case 'D': return '3';
case 'E': return '3';
case 'F': return '3';
case 'G': return '4';
case 'H': return '4';
case 'I': return '4';
case 'J': return '5';
case 'K': return '5';
case 'L': return '5';
case 'M': return '6';
case 'N': return '6';
case 'O': return '6';
case 'P': return '7';
case 'R': return '7';
case 'S': return '7';
case 'T': return '8';
case 'U': return '8';
case 'V': return '8';
case 'W': return '9';
case 'X': return '9';
case 'Y': return '9';
}
}
main ()
{
FILE *in=fopen ("namenum.in","r");
FILE *out=fopen("namenum.out","w");
FILE *dic=fopen("dict.txt","r");
char name[5000][15],fin[15],checkit[15];
int i,j,t=0;
fscanf (in,"%s",fin);
for (i=0;!feof(dic);i++)
{
memset(checkit,'\0',sizeof(checkit));
fscanf (dic,"%s",name[i]);
for (j=0;name[i][j]!='\0';j++)
checkit[j]=check(name[i][j]);
if (strcmp(fin,checkit)==0)
{
fprintf (out,"%s\n",name[i]);
t++;
}
}
if (t==0)
fprintf (out,"NONE\n");
fclose(in);
fclose(out);
fclose(dic);
exit(0);
}