#include<cstdio> |
#include<cstdlib> |
#include<cmath> |
#include<cstring> |
#include<cctype> |
#include<stack> |
#include<queue> |
#include<algorithm> |
#include<iostream> |
using namespace std; |
#define MAXN 100+5 |
int N,M; |
char str[MAXN][MAXN]; |
int pos[9][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,0},{0,1},{1,-1},{1,0},{1,1}}; |
void dfs( int x, int y) |
{ |
str[x][y]= '.' ; |
int i,j; |
for (i=0;i<9;i++) |
{ |
x+=pos[i][0]; |
y+=pos[i][1]; |
if (x>=0&&x<N&&y>=0&&y<M&&str[x][y]== 'W' ) dfs(x,y); |
x-=pos[i][0]; |
y-=pos[i][1]; |
} |
return ; |
} |
int main() |
{ |
while ( scanf ( "%d%d" ,&N,&M)!=EOF) |
{ |
int i,j; |
for (i=0;i<N;i++) |
{ |
scanf ( "%s" ,str[i]); |
} |
int ans=0; |
for (i=0;i<N;i++) |
{ |
for (j=0;j<M;j++) |
{ |
if (str[i][j]== 'W' ) |
{ |
dfs(i,j); |
ans++; |
} |
} |
} |
printf ( "%d\n" ,ans); |
} |
return 0; |
} |