/* Bajo el volc n.
Primera fase OIE 2000
Compilado con DJGPP
*/
#include <stdio.h>
#define ENTRADA "VOLCAN.DAT"
#define SALIDA "VOLCAN.RES"
int volcan[102][102];
void lava(int f, int c);
int main(void)
{
int f,c, /* filas, columnas */
x,y, /* crater */
i,j;
FILE *entrada, *salida;
entrada = fopen(ENTRADA, "r"); salida = fopen(SALIDA, "w");
if (entrada == NULL || salida == NULL) {
printf("\nError en los ficheros");
exit(1);
}
/* lee datos */
fscanf(entrada, "%d %d %d %d",&f,&c, &x, &y);
for (i = 1; i <= f; i++)
for (j = 1; j <= c; j++)
fscanf(entrada, "%d", &volcan[i][j]);
/* prepara el tablero */
for (i = 0; i <= c+1; i++) volcan[0][i] = 'X';
for (i = 0; i <= c+1; i++) volcan[f+1][i] = 'X';
for (i = 0; i <= f+1; i++) volcan[i][0] = 'X';
for (i = 0; i <= f+1; i++) volcan[i][c+1] = 'X';
/* procesa recursivamente */
lava(x,y);
/* escribe la salida */
for (i = 1; i <= f; i++) {
for (j = 1; j <= c; j++) {
if (volcan[i][j] == 'X') fprintf(salida,"X");
else fprintf(salida, "%d", volcan[i][j]);
if (j < c) fprintf(salida, " ");
}
fprintf(salida, "\n");
}
fclose(entrada);
fclose(salida);
return 0;
}
void lava(int f, int c)
{
int nf, nc, aux;
aux = volcan[f][c]; /* guarda la altura actual de la lava */
volcan[f][c] = 'X'; /* marca terreno con lava */
for (nf = f-1; nf <= f+1; nf++)
for (nc = c-1; nc <= c+1; nc++)
if (aux > volcan[nf][nc])
lava(nf,nc);
}
|