Language: C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
  	int i, j;
	int a, b; cin >> a >> b;
  	string s[a];
  	for (i=0; i<a; i++)
      cin >> s[i];
  
  	for (i=0; i<a; i++) {
		for (j=0; j<b; j++) {
          if (i==0 && j ==0) { //左上
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i].at[j+1] == '#') cnt++;
            if (s[i+1].at[j] == '#') cnt++;
            if (s[i+1].at[j+1] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (i==0 && j ==b-1) { //右上
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i].at[j-1] == '#') cnt++;
            if (s[i+1].at[j-1] == '#') cnt++;
            if (s[i+1].at[j] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (i==a-1 && j ==0) { //左下
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i-1].at[j] == '#') cnt++;
            if (s[i-1].at[j+1] == '#') cnt++;
            if (s[i].at[j+1] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (i==a-1 && j ==b-1) { //右下
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i-1].at[j-1] == '#') cnt++;
            if (s[i-1].at[j] == '#') cnt++;
            if (s[i].at[j-1] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (i==0 && (j !=0 || j != b-1)) { //上
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i].at[j-1] == '#') cnt++;
            if (s[i].at[j+1] == '#') cnt++;
            if (s[i+1].at[j-1] == '#') cnt++;
            if (s[i+1].at[j] == '#') cnt++;
            if (s[i+1].at[j+1] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (i==a-1 && (j !=0 || j != b-1)) { //下
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i-1].at[j-1] == '#') cnt++;
            if (s[i-1].at[j] == '#') cnt++;
          	if (s[i-1].at[j+1] == '#') cnt++;
            if (s[i].at[j-1] == '#') cnt++;
            if (s[i].at[j+1] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (j==0 && (i !=0 || i != a-1)) { //左
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i-1].at[j] == '#') cnt++;
          	if (s[i-1].at[j+1] == '#') cnt++;
            if (s[i].at[j+1] == '#') cnt++;
            if (s[i+1].at[j] == '#') cnt++;
            if (s[i+1].at[j+1] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (j==b-1 && (i !=0 || i != a-1)) { //右
           if (s[i].at[j] == '.') {
          	int cnt = 0;
            if (s[i-1].at[j-1] == '#') cnt++;
            if (s[i-1].at[j] == '#') cnt++;
            if (s[i].at[j-1] == '#') cnt++;
            if (s[i+1].at[j-1] == '#') cnt++;
            if (s[i+1].at[j] == '#') cnt++;
            s[i].at[j] = cnt;
           }
          }
          if (s[i].at[j] == '.') { //center
          	int cnt = 0;
            if (s[i-1].at[j-1] == '#') cnt++;
            if (s[i-1].at[j] == '#') cnt++;
          	if (s[i-1].at[j+1] == '#') cnt++;
            if (s[i].at[j-1] == '#') cnt++;
            if (s[i].at[j+1] == '#') cnt++;
            if (s[i+1].at[j-1] == '#') cnt++;
            if (s[i+1].at[j] == '#') cnt++;
            if (s[i+1].at[j+1] == '#') cnt++;
            s[i].at[j] = cnt;
          }
        }
    }
  
  	for (i=0; i<a; i++)
      cout << s[i] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   15 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:17:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   17 |             if (s[i].at[j+1] == '#') cnt++;
      |                        ^
a.cc:18:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   18 |             if (s[i+1].at[j] == '#') cnt++;
      |                          ^
a.cc:19:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   19 |             if (s[i+1].at[j+1] == '#') cnt++;
      |                          ^
a.cc:20:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   20 |             s[i].at[j] = cnt;
      |                    ^
a.cc:24:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   24 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:26:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   26 |             if (s[i].at[j-1] == '#') cnt++;
      |                        ^
a.cc:27:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   27 |             if (s[i+1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:28:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   28 |             if (s[i+1].at[j] == '#') cnt++;
      |                          ^
a.cc:29:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   29 |             s[i].at[j] = cnt;
      |                    ^
a.cc:33:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   33 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:35:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   35 |             if (s[i-1].at[j] == '#') cnt++;
      |                          ^
a.cc:36:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   36 |             if (s[i-1].at[j+1] == '#') cnt++;
      |                          ^
a.cc:37:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   37 |             if (s[i].at[j+1] == '#') cnt++;
      |                        ^
a.cc:38:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   38 |             s[i].at[j] = cnt;
      |                    ^
a.cc:42:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:44:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   44 |             if (s[i-1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:45:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   45 |             if (s[i-1].at[j] == '#') cnt++;
      |                          ^
a.cc:46:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   46 |             if (s[i].at[j-1] == '#') cnt++;
      |                        ^
a.cc:47:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   47 |             s[i].at[j] = cnt;
      |                    ^
a.cc:51:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   51 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:53:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |             if (s[i].at[j-1] == '#') cnt++;
      |                        ^
a.cc:54:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   54 |             if (s[i].at[j+1] == '#') cnt++;
      |                        ^
a.cc:55:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   55 |             if (s[i+1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:56:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   56 |             if (s[i+1].at[j] == '#') cnt++;
      |                          ^
a.cc:57:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   57 |             if (s[i+1].at[j+1] == '#') cnt++;
      |                          ^
a.cc:58:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   58 |             s[i].at[j] = cnt;
      |                    ^
a.cc:62:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   62 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:64:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   64 |             if (s[i-1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:65:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   65 |             if (s[i-1].at[j] == '#') cnt++;
      |                          ^
a.cc:66:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   66 |                 if (s[i-1].at[j+1] == '#') cnt++;
      |                              ^
a.cc:67:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   67 |             if (s[i].at[j-1] == '#') cnt++;
      |                        ^
a.cc:68:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   68 |             if (s[i].at[j+1] == '#') cnt++;
      |                        ^
a.cc:69:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   69 |             s[i].at[j] = cnt;
      |                    ^
a.cc:73:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   73 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:75:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   75 |             if (s[i-1].at[j] == '#') cnt++;
      |                          ^
a.cc:76:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   76 |                 if (s[i-1].at[j+1] == '#') cnt++;
      |                              ^
a.cc:77:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   77 |             if (s[i].at[j+1] == '#') cnt++;
      |                        ^
a.cc:78:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   78 |             if (s[i+1].at[j] == '#') cnt++;
      |                          ^
a.cc:79:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   79 |             if (s[i+1].at[j+1] == '#') cnt++;
      |                          ^
a.cc:80:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   80 |             s[i].at[j] = cnt;
      |                    ^
a.cc:84:23: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   84 |            if (s[i].at[j] == '.') {
      |                       ^
a.cc:86:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   86 |             if (s[i-1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:87:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   87 |             if (s[i-1].at[j] == '#') cnt++;
      |                          ^
a.cc:88:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   88 |             if (s[i].at[j-1] == '#') cnt++;
      |                        ^
a.cc:89:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   89 |             if (s[i+1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:90:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   90 |             if (s[i+1].at[j] == '#') cnt++;
      |                          ^
a.cc:91:20: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   91 |             s[i].at[j] = cnt;
      |                    ^
a.cc:94:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   94 |           if (s[i].at[j] == '.') { //center
      |                      ^
a.cc:96:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   96 |             if (s[i-1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:97:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   97 |             if (s[i-1].at[j] == '#') cnt++;
      |                          ^
a.cc:98:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   98 |                 if (s[i-1].at[j+1] == '#') cnt++;
      |                              ^
a.cc:99:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   99 |             if (s[i].at[j-1] == '#') cnt++;
      |                        ^
a.cc:100:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  100 |             if (s[i].at[j+1] == '#') cnt++;
      |                        ^
a.cc:101:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  101 |             if (s[i+1].at[j-1] == '#') cnt++;
      |                          ^
a.cc:102:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
  102 |             if (s[i+1].at[j] == '#') cnt++;
      |                          ^
a.cc:103:26: error: invalid types '<unresolved overloaded function t