Language: C++

//Author?¥CY
//School: CUST

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <deque>
#define inf 1<<30
using namespace std;
#define maxn 18
char str[maxn][maxn];
int n,m;
int val[maxn][maxn];
int _used[maxn][maxn];
int ans=0;
int dis[9][2]={-1,-1,-1,0,-1,1,0,-1,0,0,0,1,1,-1,1,0,1,1};
struct node
{
    int num;
    int x,y;
};
bool cmp(node a,node b)
{
    if(a.num>b.num)
        return true;
    if(b.num>a.num)
        return false;
    else if(a.y>b.y)
    {
        return true;
    }
    else
    {
        return false;
    }
}
void dfs1(int x,int y)//謇捺揀
{
    int i;
    for(i=0;i<9;i++)
    {
        int temp1=x+dis[i][0];
        int temp2=y+dis[i][1];
        if(temp1<1||temp2<1||temp1>n||temp2>m)
        {
            continue;
        }
        else if(str[temp1][temp2]=='.')
        {
            val[temp1][temp2]=-1;
            continue;
        }
        else
        {
            val[temp1][temp2]++;
        }
    }
}
void dfs3(int x,int y)
{
    int i,j,k;
     for(i=0;i<9;i++)
    {
        int temp1=x+dis[i][0];
        int temp2=y+dis[i][1];
        if(temp1<1||temp2<1||temp1>n||temp2>m)
        {
            continue;
        }
        if(str[temp1][temp2]!='.'&&str[temp1][temp2]!='*')
        {
            str[temp1][temp2]=str[temp1][temp2]-'0'-1+'0';
        }
    }
}
void dfs4(int x,int y)
{
    int i,j,k;
     for(i=0;i<9;i++)
    {
        int temp1=x+dis[i][0];
        int temp2=y+dis[i][1];
        if(temp1<1||temp2<1||temp1>n||temp2>m)
        {
            continue;
        }
        if(str[temp1][temp2]=='*'){
             _used[temp1][temp2]=1;
        }
    }
}
void dfs2(int x,int y)//雍ェ蠢?{
    _used[x][y]=1;
    int i,j,k;
    node tree[9];
    memset(tree,-1,sizeof(tree));
    for(i=0;i<9;i++)
    {
        int temp1=x+dis[i][0];
        int temp2=y+dis[i][1];
         if(temp1<1||temp2<1||temp1>n||temp2>m)
        {
            continue;
        }
        tree[i].num=val[temp1][temp2];
        tree[i].x=temp1;
        tree[i].y=temp2;
    }
    sort(tree,tree+9,cmp);
   /* for(i=0;i<9;i++)
    {
        cout<<tree[i].num<<" ";
    }
    cout<<endl;*/
    int len=str[x][y]-'0';
    if(len==0)
    {
        dfs4(x,y);
        return;
    }
    j=1;
    for(i=1;i<=len;i++)
    {
        int temp3=tree[j-1].x;
        int temp4=tree[j-1].y;
        while(str[temp3][temp4]=='*'&&_used[temp3][temp4]==1)
        {
            j++;
            temp3=tree[j-1].x;
            temp4=tree[j-1].y;
        }
        dfs3(temp3,temp4);
        _used[temp3][temp4]=1;
       // cout<<temp3<<" "<<temp4<<" ";
        ans++;
        j++;
    }
    dfs4(x,y);
    //cout<<endl;
}
int main()
{

    while(cin>>n>>m){
        if(n==0&&m==0)
        {
            return 0;
        }
            ans=0;
    int i,j,k;
    memset(val,0,sizeof(val));
    memset(_used,0,sizeof(_used));
    for(i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        for(j=1;j<=m;j++)
        {
            str[i][j]=s[j-1];
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(str[i][j]!='.'&&str[i][j]!='*')
            {
                dfs1(i,j);
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(str[i][j]!='.'&&str[i][j]!='*')
            {
                dfs2(i,j);
            }
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}

Compiler output:
a.cc:102:5: error: expected initializer before '_used'
  102 |     _used[x][y]=1;
      |     ^~~~~
a.cc:105:11: error: expected constructor, destructor, or type conversion before '(' token
  105 |     memset(tree,-1,sizeof(tree));
      |           ^
a.cc:106:5: error: expected unqualified-id before 'for'
  106 |     for(i=0;i<9;i++)
      |     ^~~
a.cc:106:13: error: 'i' does not name a type
  106 |     for(i=0;i<9;i++)
      |             ^
a.cc:106:17: error: 'i' does not name a type
  106 |     for(i=0;i<9;i++)
      |                 ^
a.cc:118:9: error: expected constructor, destructor, or type conversion before '(' token
  118 |     sort(tree,tree+9,cmp);
      |         ^
a.cc:124:17: error: 'x' was not declared in this scope
  124 |     int len=str[x][y]-'0';
      |                 ^
a.cc:124:20: error: 'y' was not declared in this scope; did you mean 'yn'?
  124 |     int len=str[x][y]-'0';
      |                    ^
      |                    yn
a.cc:125:5: error: expected unqualified-id before 'if'
  125 |     if(len==0)
      |     ^~
a.cc:130:5: error: 'j' does not name a type
  130 |     j=1;
      |     ^
a.cc:131:5: error: expected unqualified-id before 'for'
  131 |     for(i=1;i<=len;i++)
      |     ^~~
a.cc:131:13: error: 'i' does not name a type
  131 |     for(i=1;i<=len;i++)
      |             ^
a.cc:131:20: error: 'i' does not name a type
  131 |     for(i=1;i<=len;i++)
      |                    ^
a.cc:147:9: error: expected constructor, destructor, or type conversion before '(' token
  147 |     dfs4(x,y);
      |         ^
a.cc:149:1: error: expected declaration before '}' token
  149 | }
      | ^
a.cc: In function 'int main()':
a.cc:187:17: error: 'dfs2' was not declared in this scope; did you mean 'dfs4'?
  187 |                 dfs2(i,j);
      |                 ^~~~
      |                 dfs4