728x90
#include<iostream>
#include<vector>
#include<map>
#include<cstring>
using namespace std;
int n;
vector<vector<char>>arr(10, vector<char>(10));
vector<vector<char>>openArr(10, vector<char>(10));
vector<vector<char>>answer(10, vector<char>(10,'.'));
int dx[] = {0,0,1,-1,1,-1,1,-1};
int dy[] = {1,-1,0,0,1,1,-1,-1};
bool cango( int x , int y ) {
return x >= 0 && x < n && y >= 0 && y < n;
}
void findAllStars() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (arr[i][j] == '*') {
answer[i][j] = '*';
}
}
}
}
char findnum(int x, int y) {
int num = 0;
int nx, ny;
for (int i = 0; i < 8; i++) {
nx = x + dx[i];
ny = y + dy[i];
if (cango(nx, ny)) {
if (arr[nx][ny] == '*') { num++; }
}
}
return '0' + num;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> openArr[i][j];
}
}
bool toggle = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (openArr[i][j] == 'x') {
if (arr[i][j] == '*') { toggle = true; }
answer[i][j] = findnum(i, j);
}
}
}
if (toggle == true) {
findAllStars();
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << answer[i][j];
}
cout << endl;
}
}