#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int x[] = {-1, 0, 1, 0};
int y[] = {0, 1, 0, -1};
char s[1000][1001];
int n, m;
bool bound(int cx, int cy) {
if (cx >= 0 && cx < n && cy >= 0 && cy < m)
return true;
return false;
}
int dfs(int cx, int cy) {
int nx, ny, nr = 0;
if (s[cx][cy] == '*')
nr++;
s[cx][cy] = '#';
for (int i = 0; i < 4; i++) {
nx = cx + x[i];
ny = cy + y[i];
if (bound(nx, ny) && s[nx][ny] != '#')
nr += dfs(nx, ny);
}
return nr;
}
int main(int argc, char* argv[]) {
int i, j, cx, cy;
bool mark;
while (scanf("%d", &n) != EOF) {
scanf("%d", &m);
mark = false;
for (i = 0; i < n; i++) {
scanf("%s", s[i]);
if (mark)
continue;
for (j = 0; j < m; j++) {
if (s[i][j] == 'X') {
cx = i;
cy = j;
mark = true;
break;
}
}
}
printf("%d\n", dfs(cx, cy));
}
return 0;
}
|