Hello, My code is:
/***********************
solution to problem ,
by: Adrian Michel
date: 06/03/2007
***********************/
#include<stdio.h>
#include<string.h>
main(){
char Minesweeper[100][100];
int NFilas, NColumnas, li, lj, ContBombs, ContFields;
ContFields = 1;
do{
/* Captura del Numero de Filas y Columnas */
scanf("%d %d", &NFilas, &NColumnas);
fflush(stdin);
/* Captura del tablero de Minesweeper */
if( (NFilas > 0) && (NColumnas > 0) )
{
for ( li = 0; li < NFilas; li ++ )
{
for ( lj = 0; lj < NColumnas; lj++ )
{
scanf("%c", &Minesweeper[li][lj]);
}
fflush(stdin);
} /*Fin Captura*/
/* Transformacion de la Matriz*/
for ( li = 0;li < NFilas; li++ )
{
for ( lj = 0; lj < NColumnas; lj++)
{
if ( Minesweeper[li][lj] =='.' )
{
ContBombs = 0;
if ( (li-1 >=0) && (lj-1 >= 0) &&
( Minesweeper[li-1][lj-1] == '*' ) )
{
ContBombs ++;
}
if ( (lj-1 >= 0) &&
( Minesweeper[li][lj-1] == '*' ) )
{
ContBombs ++;
}
if ( (li+1 < NFilas) && (lj-1 >= 0) &&
( Minesweeper[li+1][lj-1] == '*' ) )
{
ContBombs ++;
}
if ( (li-1 >=0) && (lj+1 < NColumnas) &&
( Minesweeper[li-1][lj+1] == '*' ) )
{
ContBombs ++;
}
if ( (lj+1 < NColumnas) &&
( Minesweeper[li][lj+1] == '*' ) )
{
ContBombs ++;
}
if ( (li+1 < NFilas) && (lj+1 < NColumnas) &&
( Minesweeper[li+1][lj+1] == '*' ) )
{
ContBombs ++;
}
if ( (li-1 >= 0) &&
( Minesweeper[li-1][lj] == '*' ) )
{
ContBombs ++;
}
if ( (li+1 < NFilas) &&
( Minesweeper[li+1][lj] == '*' ) )
{
ContBombs ++;
}
switch (ContBombs)
{
case 0:
Minesweeper[li][lj] = '0';
break;
case 1:
Minesweeper[li][lj] = '1';
break;
case 2:
Minesweeper[li][lj] = '2';
break;
case 3:
Minesweeper[li][lj] = '3';
break;
case 4:
Minesweeper[li][lj] = '4';
break;
case 5:
Minesweeper[li][lj] = '5';
break;
case 6:
Minesweeper[li][lj] = '6';
break;
case 7:
Minesweeper[li][lj] = '7';
break;
case 8:
Minesweeper[li][lj] = '8';
break;
} /*Fin Switch*/
} /*Fin Si '.'*/
} /*Fin For lj*/
}/*Fin For li*/
/*Mostrar Resultados*/
printf ("Field #%d:\n", ContFields);
for ( li = 0;li < NFilas; li++ )
{
for ( lj = 0; lj < NColumnas; lj++)
{
printf ("%c", Minesweeper[li][lj]);
}
printf("\n");
} /*Fin For Imprime*/
printf ("\n");
ContFields ++;
}
}while(NFilas > 0 && NColumnas > 0);
return 0;
}
online-Judged Output Limit Exceeded!!, Why?
