1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <iostream>
using namespace std;
const int MAX = 101;
int asd[202]; int n, m; int ans = 0; char c; int map[MAX][MAX];
void digui(int a, int b, int k) { if (a >= 0 & & a < n & & b >= 0 & & b < m & & map[a][b] == -2) { map[a][b] = k; digui(a + 1, b, k); digui(a, b + 1, k); digui(a - 1, b, k); digui(a, b - 1, k); digui(a + 1, b + 1, k); digui(a + 1, b - 1, k); digui(a - 1, b + 1, k); digui(a - 1, b - 1, k); } }
int main() {
int i, j;
cin >> n >> m; for (i = 0; i < n; i++) { for (j = 0; j < m; j++){ cin >> c; if (c == 'W') map[i][j] = -2; else map[i][j] = 0; } } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (map[i][j] == -2) { ans++; digui(i, j, ans); } } } cout << ans << endl; return 0; }
|
Checking if Disqus is accessible...