/BCBOM - Trò chơi dò mìn

<Problem>

https://www.spoj.com/PTIT/problems/BCBOM/
              #include <iostream>
        using namespace std;
         
        int main() {
          int n, m;
          cin >> n >> m;
          if (n == 0) return 0;
          while (n != 0) {
            char str[200][200];
         
            for (int i = 0; i < 200; i++) {
              for (int j = 0; j < 200; j++) {
                str[i][j] = '.';
              }
            }
         
            for (int i = 1; i <= n; i++) {
              for (int j = 1; j <= m; j++) {
                cin >> str[i][j];
              }
            }
         
            int* f = new int[200000] { 0 };
         
            for (int i = 1; i <= n; i++) {
              for (int j = 1; j <= m; j++) {
                if (str[i][j] == '.') {
                  int c = 1;
                  if (str[i - 1][j] == '*') c++;
                  if (str[i - 1][j - 1] == '*') c++;
                  if (str[i - 1][j + 1] == '*') c++;
                  if (str[i][j - 1] == '*') c++;
                  if (str[i][j + 1] == '*') c++;
                  if (str[i + 1][j] == '*') c++;
                  if (str[i + 1][j - 1] == '*') c++;
                  if (str[i + 1][j + 1] == '*') c++;
                  f[(i - 1) * m + j] = c;
                  //cout << i << "-" << j << "-" << c << endl;
                }
              }
            }
         
            for (int i = 1; i <= n * m; i++) {
              //cout << "+" << f[i] << "+";
              if (f[i] > 0) cout << f[i] - 1;
              else cout << '*';
              if (i % m == 0) cout << endl;
            }
            cin >> n >> m;
         
          }
          return 0;
        }