func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 1010;   string a[MAX];   int n, m;   bool visit[MAX][MAX];   bool v[1000010];   int b[MAX][MAX];   int val[1000010];   void dfs(int x, int y, int cnt) {     if (x < 0 || y < 0 || x >= n || y >= m) {       return;     }     if (visit[x][y]) {       return;     }     if (a[x][y] ==  * ) {       return;     }     visit[x][y] = true;     val[cnt]++;     b[x][y] = cnt;     dfs(x + 1, y, cnt);     dfs(x, y + 1, cnt);     dfs(x - 1, y, cnt);     dfs(x, y - 1, cnt);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     memset(visit, false, sizeof(visit));     memset(b, -1, sizeof(visit));     memset(val, 0, sizeof(val));     int cnt = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visit[i][j] && a[i][j] ==  . ) {           dfs(i, j, cnt);           cnt++;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  * ) {           int temp = 1, t[5] = {0};           if (b[i - 1][j] != -1 && i - 1 >= 0) {             t[0] = b[i - 1][j];           }           if (b[i][j - 1] != -1 && j - 1 >= 0) {             t[1] = b[i][j - 1];           }           if (b[i + 1][j] != -1 && i + 1 < n) {             t[2] = b[i + 1][j];           }           if (b[i][j + 1] != -1 && j + 1 < m) {             t[3] = b[i][j + 1];           }           sort(t, t + 4);           for (int k = 0; k < 4; k++) {             if (t[k] != t[k + 1]) {               temp += val[t[k]];             }           }           a[i][j] =  0  + (temp) % 10;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] <<   n ;     }     return 0;   }   