#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ENTRADA "SOP.DAT"
#define SALIDA "SOP.RES"
FILE *FileIn,*FileOut;
int x,y;
char Tabla[105][105];
char Palabra[25];
int DirX[8]={1,-1,0,0,1,-1,-1,1};
int DirY[8]={0,0,1,-1,1,-1,1,-1};
void Buscar();
int main()
{
int i,j,n;
FileIn=fopen(ENTRADA,"r");
FileOut=fopen(SALIDA,"w");
if (FileIn==NULL || FileOut==NULL) exit(1);
fscanf(FileIn,"%d %d\n",&x,&y);
for (i=0; i<x; i++)
{
for (j=0; j<y; j++)
fscanf(FileIn,"%c",&Tabla[i][j]);
fgetc(FileIn);
}
fscanf(FileIn,"%d",&n);
for (i=0; i<n; i++)
{
fscanf(FileIn,"%s",&Palabra);
Buscar();
if (i!=n-1) fprintf(FileOut,"\n");
}
return 0;
}
void Buscar()
{
int i,j,d,a,b,p,letras;
int fin=0;
letras=strlen(Palabra);
for (i=0; i<x && !fin; i++)
{
for (j=0; j<y && !fin; j++)
for (d=0; d<8 && !fin; d++)
{
for (a=i,b=j,p=1;
Palabra[p-1]==Tabla[a][b] && p<=letras &&
a>=0 && a<x && b>=0 && b<y;
p++,a+=DirX[d],b+=DirY[d])
if (p==letras)
{
fprintf(FileOut,"%d %d %d %d",i+1,j+1,a+1,b+1);
fin=1;
}
}
}
if (fin==0) fprintf(FileOut,"???");
}
|