#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main() {
    int dx[8] = {-1,-1,-1,0,0,1,1,1};
    int dy[8] = {-1,0,1,-1,1,-1,0,1};
    
    int n;
    cin >> n;

    vector<string> boom(n);
    vector<string> find(n);
    vector<string> big9(n, string(n, '.'));

    for (int i = 0; i < n; i++) cin >> boom[i];
    for (int i = 0; i < n; i++) cin >> find[i];

    bool a = false;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (find[i][j] == 'x' && boom[i][j] == '*') {
                a = true;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {

            if (find[i][j] == 'x') {
                if (boom[i][j] == '*') {
                    big9[i][j] = '*';
                } else {
                    int cnt = 0;
                    for (int d = 0; d < 8; d++) {
                        int ni = i + dx[d];
                        int nj = j + dy[d];
                        if (ni >= 0 && ni < n && nj >= 0 && nj < n) {
                            if (boom[ni][nj] == '*') cnt++;
                        }
                    }
                    big9[i][j] = cnt + '0';
                }
            }
        }
    }
    if (a) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (boom[i][j] == '*')
                    big9[i][j] = '*';
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << big9[i] << '\n';
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: