
this is an easy one........ but I still always get wrong answer when submitting to the online judge, I have tested the program with some cases and getting all-correct result.
May anyone please help me to see what's go wrong....?? thanks!!
[c]
/* @JUDGE_ID: 27296JC 10189 C "aaa" */
/* CSC1140@ 02759173 jl3Rjjtv 10189*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
/* height and width store the input height and width of the board */
int i, j, height, width, cno;
/* the board stores the minesweeper board */
char board[200][200];
char temp[200][200];
for(cno = 0; ; cno++)
{
/* get the height and width of the first board */
scanf("%d %d", &height, &width);
if(height == 0 && width == 0)
break;
if(cno > 0)
printf("\n");
/* get the input board */
for (i=0; i< height; i++)
scanf("%s", board[i]);
for (i=0; i<200; i++){
for (j=0;j<200; j++){
temp[i][j]=48;
}
}
for (i=0;i<width;i++){
for (j=0;j<height;j++){
if (board[i][j]=='*'){
if (i>0 && j>0 && board[i-1][j-1]!='*'){ temp[i-1][j-1]+=1;}
if (j>0 && board[i][j-1]!='*'){ temp[i][j-1]+=1;}
if (i<200-1 && j>0 && board[i+1][j-1]!='*'){ temp[i+1][j-1]+=1;}
if (i>0 && board[i-1][j]!='*'){ temp[i-1][j]+=1;}
if (i<200-1 && board[i+1][j]!='*') {temp[i+1][j]+=1;}
if (i>0 && j<200-1 && board[i-1][j+1]!='*'){ temp[i-1][j+1]+=1;}
if (j<200-1 && board[i][j+1]!='*') {temp[i][j+1]+=1;}
if (j<200-1 && board[i+1][j+1]!='*') {temp[i+1][j+1]+=1;}
temp[i][j]='*';
}
}
}
printf("Field #%d:\n", cno + 1);
for (i=0; i< height; i++)
{
for (j=0; j< width; j++)
printf("%c", temp[i][j]);
printf("\n");
}
}
return 0;
}
[/c]