ac

123  •  2天前


include <bits/stdc++.h>

using namespace std;

int h, w, maxa; int fx[4] = {-1, 0, 1, 0};

int fy[4] = {0, -1, 0, 1}; char a[51][51], b, c;

int dfs(int x, int y) {

maxa++;
a[x][y] = '#';
for (int i = 0; i < 4; i++) {
	int dx = x + fx[i];
	int dy = y + fy[i];
	if (a[dx][dy] == '.') {
		dfs(dx, dy);
	}

}
return maxa;

}

int main() {

cin >> h >> w;
for (int i = 1; i <= w; i++) {
	for (int j = 1; j <= h; j++) {
		cin >> a[i][j];
		if (a[i][j] == '@') {
			b = i;
			c = j;
		}
	}
}
dfs(b, c);
cout << maxa;
return 0;

}


评论:

请先登录,才能进行评论