Created
January 25, 2014 08:44
-
-
Save KT-Yeh/8613562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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