#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <map>
#include <vector>
using namespace std;
int main(){
int row, col, cs = 0, blank = 0;
while(cin >> row >> col){
if(!row && !col)break;
int cnt[row+3][col+3];
memset(cnt, 0, sizeof(cnt));
char input;
getchar();
for(int i = 0; i < row; i++)
for(int j = 0; j < col; j++){
cin >> input;
if(input == '*'){
cnt[i][j] = -3;
if(cnt[i+1][j] != -3)cnt[i+1][j]++;
if(cnt[i][j+1] != -3)cnt[i][j+1]++;
if(cnt[i-1][j] != -3)cnt[i-1][j]++;
if(cnt[i][j-1] != -3)cnt[i][j-1]++;
if(cnt[i+1][j+1] != -3)cnt[i+1][j+1]++;
if(cnt[i-1][j-1] != -3)cnt[i-1][j-1]++;
if(cnt[i+1][j-1] != -3)cnt[i+1][j-1]++;
if(cnt[i-1][j+1] != -3)cnt[i-1][j+1]++;
}
}
if(blank)cout << endl;
cout << "Field #" << ++cs << ":" << endl;
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
if(cnt[i][j] == -3)cout << "*";
else cout << cnt[i][j];
}cout << endl;
}blank = 1;
}
return 0;
}
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <map>
#include <vector>
using namespace std;
int main(){
int row, col, cs = 0, blank = 0;
while(cin >> row >> col){
if(!row && !col)break;
int cnt[row+3][col+3];
memset(cnt, 0, sizeof(cnt));
char input;
getchar();
for(int i = 0; i < row; i++)
for(int j = 0; j < col; j++){
cin >> input;
if(input == '*'){
cnt[i][j] = -3;
if(cnt[i+1][j] != -3)cnt[i+1][j]++;
if(cnt[i][j+1] != -3)cnt[i][j+1]++;
if(cnt[i-1][j] != -3)cnt[i-1][j]++;
if(cnt[i][j-1] != -3)cnt[i][j-1]++;
if(cnt[i+1][j+1] != -3)cnt[i+1][j+1]++;
if(cnt[i-1][j-1] != -3)cnt[i-1][j-1]++;
if(cnt[i+1][j-1] != -3)cnt[i+1][j-1]++;
if(cnt[i-1][j+1] != -3)cnt[i-1][j+1]++;
}
}
if(blank)cout << endl;
cout << "Field #" << ++cs << ":" << endl;
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
if(cnt[i][j] == -3)cout << "*";
else cout << cnt[i][j];
}cout << endl;
}blank = 1;
}
return 0;
}
No comments:
Post a Comment