```cpp
#include<bits/stdc++.h>
using namespace std;
int dx[]={0,0,-1,1},dy[]={1,-1,0,0},cnt,n,m;
char ch[120][120];
bool f[120][120];
void dfs(int r,int c){
for(int i=0;i<4;i++){
int nr=r+dx[i];
int nc=c+dy[i];
if(1<=nr&&nr<=n&&1<=nc&&nc<=m&&ch[nr][nc]>='1'&&ch[nr][nc]<='9'&&!f[nr][nc]){
f[nr][nc]=true;
dfs(nr,nc);
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>ch[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(ch[i][j]>='1'&&ch[i][j]<='9'&&!f[i][j]){
cnt++;
f[i][j]=true;
dfs(i,j);
}
}
}
cout<<cnt;
return 0;
}
by chenhongyu20100506 @ 2021-10-17 21:41:03