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(H>1 && W>1){
                        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]++;
                                }
                        }
                  }
                }
                    if(H==1 && W==2){
                      if(s[0].at(0)=='#')
                        count[0][1]++;
                      if(s[0].at(1)=='#')
                        count[0][0]++;
                    }
                    if(H==2 && W==1){
                      if(s[0].at(0)=='#')
                        count[1][0]++;
                      if(s[1].at(0)=='#')
                        count[0][0]++;
                    }
                  }
                }
        }
        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:132:9: error: expected declaration before '}' token
  132 |         }
      |         ^
a.cc:133:9: error: expected unqualified-id before 'for'
  133 |         for(i=0; i<H; i++){
      |         ^~~
a.cc:133:18: error: 'i' does not name a type
  133 |         for(i=0; i<H; i++){
      |                  ^
a.cc:133:23: error: 'i' does not name a type
  133 |         for(i=0; i<H; i++){
      |                       ^
a.cc:142:1: error: expected declaration before '}' token
  142 | }
      | ^