#include #include #include using namespace std; vector sky; void fill(int i, int j) { sky[i][j] = '+'; for(int ii : {-1, 0, 1}) for(int jj : {-1, 0, 1}) { if (ii*jj != 0 || ii==jj) continue; if (sky[i+ii][j+jj] == '-') fill(i+ii, j+jj); } } int main() { int m, n, t = 0; while (cin >> m >> n) { ++t; sky = vector(m+2, string(n+2, '#')); for (int i = 0; i < m; ++i) { string s; cin >> s; sky[i+1] = "#" + s + "#"; } int c = 0; for (int i = 1; i <= m; ++i) for (int j = 1; j <= n; ++j) if (sky[i][j] == '-') { ++c; fill(i, j); } cout << "Case " << t << ": " << c << endl; } return 0; }