Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created January 25, 2014 08:44
Show Gist options
  • Save KT-Yeh/8613562 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8613562 to your computer and use it in GitHub Desktop.
#include <cstdio>
using namespace std;
int n,m;
char field[105][105];
void Fill (int x,int y)
{
for (int i=-1; i<=1; i++)
for (int j=-1; j<=1; j++)
if (field[x+i][y+j]!='*')
field[x+i][y+j]++;
}
int main()
{
// freopen("input.txt","rt",stdin);
int T = 1;
while (scanf("%d %d",&n,&m))
{
if (!n && !m) break;
if (T!=1) printf("\n");
//初始化數量為0
for(int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
field[i][j]='0';
//輸入,如果為'*',則呼叫Fill將其八個方向數量+1
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
char c;
c = getchar();
while (c=='\n') c = getchar();
if (c == '*'){
field[i][j]='*';
Fill(i,j);
}
}
}
//輸出結果
printf("Field #%d:\n",T++);
for (int i=1; i<=n; i++){
for (int j=1; j<=m; j++)
printf("%c",field[i][j]);
printf("\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment