#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int Norte (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
j = *pc; k = 0;
for (i = *pl; i < i+n; i++) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pl = i;
return 0;
}
int Sul (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
j = *pc; k = 0;
for (i = *pl; i < i+n; i++) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pl = i;
return 0;
}
int Leste (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
i = *pl; k = 0;
for (j = *pc; j < j+n; j++) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pc = j;
return 0;
}
int Oeste (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
i = *pl; k = 0;
for (j = *pc; j < j+n; j--) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pc = j;
return 0;
}
int Nordeste (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
k = 0;
for (i = *pl, j = *pc; i < i+n; j++, i--) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pl = i; *pc = j;
return 0;
}
int Noroeste (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
k = 0;
for (i = *pl, j = *pc; i < i+n; j--, i--) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pl = i; *pc = j;
return 0;
}
int Sudeste (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
k = 0;
for (i = *pl, j = *pc; i < i+n; j--, i++) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pl = i; *pc = j;
return 0;
}
int Sudoeste (char cacapalavra[][100], char palavra[], int *pc, int *pl) {
int i, j, n, k;
k = 0;
for (i = *pl, j = *pc; i < i+n; j++, i++) {
if (cacapalavra [i][j] != palavra[k]) return -1;
else k++;
}
*pl = i; *pc = j;
return 0;
}
int main () {
char cacapalavra [100][100];
char palavra [100];
int i, j, k, n, *pc = 0, *pl = 0, aux;
k = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
scanf ("%c", &cacapalavra
[i
][j
]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (palavra[k] == cacapalavra[i][j]) {
*pc = j; *pl = i;
aux = Norte(cacapalavra, palavra, pc, pl);
aux = Sul(cacapalavra, palavra, pc, pl);
aux = Leste(cacapalavra, palavra, pc, pl);
aux = Oeste(cacapalavra, palavra, pc, pl);
aux = Nordeste(cacapalavra, palavra, pc, pl);
aux = Noroeste(cacapalavra, palavra, pc, pl);
aux = Sudeste(cacapalavra, palavra, pc, pl);
aux = Sudoeste(cacapalavra, palavra, pc, pl);
printf("%d", aux
); //só para eliminar o warning que não foi usada. }
}
}
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPHN0ZGxpYi5oPgoKaW50IE5vcnRlIChjaGFyIGNhY2FwYWxhdnJhW11bMTAwXSwgY2hhciBwYWxhdnJhW10sIGludCAqcGMsIGludCAqcGwpIHsKICAgIGludCBpLCBqLCBuLCBrOwogICAgaiA9ICpwYzsgayA9IDA7CiAgICBuID0gc3RybGVuKHBhbGF2cmEpOwogICAgZm9yIChpID0gKnBsOyBpIDwgaStuOyBpKyspIHsKICAgICAgICAgICAgaWYgKGNhY2FwYWxhdnJhIFtpXVtqXSAhPSBwYWxhdnJhW2tdKSByZXR1cm4gLTE7CiAgICAgICAgICAgIGVsc2UgaysrOwogICAgfQogICAgKnBsID0gaTsKICAgIHJldHVybiAwOwp9CgppbnQgU3VsIChjaGFyIGNhY2FwYWxhdnJhW11bMTAwXSwgY2hhciBwYWxhdnJhW10sIGludCAqcGMsIGludCAqcGwpIHsKICAgIGludCBpLCBqLCBuLCBrOwogICAgaiA9ICpwYzsgayA9IDA7CiAgICBuID0gc3RybGVuKHBhbGF2cmEpOwoKICAgIGZvciAoaSA9ICpwbDsgaSA8IGkrbjsgaSsrKSB7CiAgICAgICAgICAgIGlmIChjYWNhcGFsYXZyYSBbaV1bal0gIT0gcGFsYXZyYVtrXSkgcmV0dXJuIC0xOwogICAgICAgICAgICBlbHNlIGsrKzsKICAgIH0KICAgICpwbCA9IGk7CiAgICByZXR1cm4gMDsKfQoKaW50IExlc3RlIChjaGFyIGNhY2FwYWxhdnJhW11bMTAwXSwgY2hhciBwYWxhdnJhW10sIGludCAqcGMsIGludCAqcGwpIHsKICAgIGludCBpLCBqLCBuLCBrOwogICAgaSA9ICpwbDsgayA9IDA7CiAgICBuID0gc3RybGVuKHBhbGF2cmEpOwoKICAgIGZvciAoaiA9ICpwYzsgaiA8IGorbjsgaisrKSB7CiAgICAgICAgICAgIGlmIChjYWNhcGFsYXZyYSBbaV1bal0gIT0gcGFsYXZyYVtrXSkgcmV0dXJuIC0xOwogICAgICAgICAgICBlbHNlIGsrKzsKICAgIH0KICAgICpwYyA9IGo7CiAgICByZXR1cm4gMDsKfQoKaW50IE9lc3RlIChjaGFyIGNhY2FwYWxhdnJhW11bMTAwXSwgY2hhciBwYWxhdnJhW10sIGludCAqcGMsIGludCAqcGwpIHsKICAgIGludCBpLCBqLCBuLCBrOwogICAgaSA9ICpwbDsgayA9IDA7CiAgICBuID0gc3RybGVuKHBhbGF2cmEpOwoKICAgIGZvciAoaiA9ICpwYzsgaiA8IGorbjsgai0tKSB7CiAgICAgICAgICAgIGlmIChjYWNhcGFsYXZyYSBbaV1bal0gIT0gcGFsYXZyYVtrXSkgcmV0dXJuIC0xOwogICAgICAgICAgICBlbHNlIGsrKzsKICAgIH0KICAgICpwYyA9IGo7CiAgICByZXR1cm4gMDsKfQoKaW50IE5vcmRlc3RlIChjaGFyIGNhY2FwYWxhdnJhW11bMTAwXSwgY2hhciBwYWxhdnJhW10sIGludCAqcGMsIGludCAqcGwpIHsKICAgICBpbnQgaSwgaiwgbiwgazsKICAgICBrID0gMDsKICAgICBuID0gc3RybGVuKHBhbGF2cmEpOwoKICAgICBmb3IgKGkgPSAqcGwsIGogPSAqcGM7IGkgPCBpK247IGorKywgaS0tKSB7CiAgICAgICAgICAgIGlmIChjYWNhcGFsYXZyYSBbaV1bal0gIT0gcGFsYXZyYVtrXSkgcmV0dXJuIC0xOwogICAgICAgICAgICBlbHNlIGsrKzsKICAgICB9CiAgICAgKnBsID0gaTsgKnBjID0gajsKICAgICByZXR1cm4gMDsKfQoKaW50IE5vcm9lc3RlIChjaGFyIGNhY2FwYWxhdnJhW11bMTAwXSwgY2hhciBwYWxhdnJhW10sIGludCAqcGMsIGludCAqcGwpIHsKICAgICBpbnQgaSwgaiwgbiwgazsKICAgICBrID0gMDsKICAgICBuID0gc3RybGVuKHBhbGF2cmEpOwoKICAgICBmb3IgKGkgPSAqcGwsIGogPSAqcGM7IGkgPCBpK247IGotLSwgaS0tKSB7CiAgICAgICAgICAgIGlmIChjYWNhcGFsYXZyYSBbaV1bal0gIT0gcGFsYXZyYVtrXSkgcmV0dXJuIC0xOwogICAgICAgICAgICBlbHNlIGsrKzsKICAgICB9CiAgICAgKnBsID0gaTsgKnBjID0gajsKICAgICByZXR1cm4gMDsKfQoKaW50IFN1ZGVzdGUgKGNoYXIgY2FjYXBhbGF2cmFbXVsxMDBdLCBjaGFyIHBhbGF2cmFbXSwgaW50ICpwYywgaW50ICpwbCkgewogICAgIGludCBpLCBqLCBuLCBrOwogICAgIGsgPSAwOwogICAgIG4gPSBzdHJsZW4ocGFsYXZyYSk7CgogICAgIGZvciAoaSA9ICpwbCwgaiA9ICpwYzsgaSA8IGkrbjsgai0tLCBpKyspIHsKICAgICAgICAgICAgIGlmIChjYWNhcGFsYXZyYSBbaV1bal0gIT0gcGFsYXZyYVtrXSkgcmV0dXJuIC0xOwogICAgICAgICAgICAgZWxzZSBrKys7CiAgICAgfQogICAgICpwbCA9IGk7ICpwYyA9IGo7CiAgICAgcmV0dXJuIDA7Cn0KCmludCBT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