#include<bits/stdc++.h>
using namespace std;
int n,m,head=0,tail=0;
int q[10005][2];
char a[115][115];
bool b[115][115];
int wx[8]={-1,-1,00,+1,+1,+1,00,-1};
int wy[8]={00,+1,+1,+1,00,-1,-1,-1};
void bfs(int sx,int sy){
tail++;
q[tail][0]=sx;
q[tail][1]=sy;
while(head<tail){
head++;
int x=q[head][0],y=q[head][1];
for(int i=0;i<8;i++){
int nx=x+wx[i],ny=y+wy[i];
if(b[nx][ny]==1){
b[nx][ny]=0;
tail++;
q[tail][0]=nx;
q[tail][1]=ny;
}
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]=='W') b[i][j]=1;
else b[i][j]=0;
}
}
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
head=0;tail=0;
memset(q,0,sizeof(q));
if(b[i][j]==1){
ans++;
bfs(i,j);
}
}
}
cout<<ans;
return 0;
}
11-11
360
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-08
1367
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)