Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
        int H,W;
        int i,j;
        string s[50];
        int count[50][50];
        cin >> H >> W;
        for(i=0; i<H; i++){
                cin >> s[i];
        }
        for(i=0; i<H; i++){
                for(j=0; j<W; j++){
                        if(s[i].at(j)=='.'){
                                if(i==0 && j==0){
                                        if(s[i].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j+1)=='#')
                                                count[i][j]++;
                                }
                                else if(i==0 && j==W-1){
                                        if(s[i].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j-1)=='#')
                                                count[i][j]++;
                                }
                                else if(i==H-1 && j==0){
                                        if(s[i-1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j+1)=='#')
                                                count[i][j]++;
                                }
                                else if(i==H-1 && j==W-1){
                                        if(s[i-1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j-1)=='#')
                                                count[i][j]++;
                                }
                           　　　else if(i==0 && j!=0 && j!=W-1){
                                        if(s[i].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j+1)=='#')
                                                count[i][j]++;
                                }
                                else if(j==0 && i!=0 && i!=H-1){
                                        if(s[i-1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j+1)=='#')
                                                count[i][j]++;
                                }
                                else if(j==W-1 && i!=0 && i!=H-1){
                                        if(s[i-1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j)=='#')
                                                count[i][j]++;
                                }
                                else if(i==H-1 && j!=0 && j!=W-1){
                                        if(s[i-1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j+1)=='#')
                                                count[i][j]++;
                                }
　　　　　　　　　　　　　　　　　　else{
                                        if(s[i-1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i-1].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i].at(j+1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j-1)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j)=='#')
                                                count[i][j]++;
                                        if(s[i+1].at(j+1)=='#')
                                                count[i][j]++;
                                }
                        }
                }
        }
for(i=0; i<H; i++){
                for(j=0; j<W; j++){
                        if(s[i].at(j)=='.')
                                cout << count[i][j];
                        else
                                cout << s[i].at(j);
                }
                cout << endl;
        }
}



Compiler output:
a.cc:48:28: error: extended character 　 is not valid in an identifier
   48 |                            　　　else if(i==0 && j!=0 && j!=W-1){
      |                            ^
a.cc:48:28: error: extended character 　 is not valid in an identifier
a.cc:48:28: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
   96 | 　　　　　　　　　　　　　　　　　　else{
      | ^
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc:96:1: error: extended character 　 is not valid in an identifier
a.cc: In function 'int main()':
a.cc:48:28: error: '\U00003000\U00003000\U00003000else' was not declared in this scope
   48 |                            　　　else if(i==0 && j!=0 && j!=W-1){
      |                            ^~~~~~~~~~
a.cc:60:33: error: expected '}' before 'else'
   60 |                                 else if(j==0 && i!=0 && i!=H-1){
      |                                 ^~~~
a.cc:15:44: note: to match this '{'
   15 |                         if(s[i].at(j)=='.'){
      |                                            ^
a.cc:96:1: error: '\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000\U00003000else' was not declared in this scope
   96 | 　　　　　　　　　　　　　　　　　　else{
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: At global scope:
a.cc:117:1: error: expected unqualified-id before 'for'
  117 | for(i=0; i<H; i++){
      | ^~~
a.cc:117:10: error: 'i' does not name a type
  117 | for(i=0; i<H; i++){
      |          ^
a.cc:117:15: error: 'i' does not name a type
  117 | for(i=0; i<H; i++){
      |               ^
a.cc:126:1: error: expected declaration before '}' token
  126 | }
      | ^