#include #include int line0[1000]; int line1[1000]; int widths[1000]; int begins[1000]; void do_nothing() {} void swap_lines(int **l1, int **l2) { int *tmp; tmp = *l1; *l1 = *l2; *l2 = tmp; } int main() { int R, C; int i, j; int ships; int *line; int *last_line; int c; int old_c; while (scanf("%d %d\n", &R, &C) == 2) { if (R == 0 && C == 0) break; line = line0; last_line = line1; for (i = 0; i < C; i++) { last_line[i] = 0; widths[i] = 0; begins[i] = 0; } ships = 0; for (i = 0; i < R; i++) { int is_new = 1; int first_in_col = 1; c = '.'; for (j = 0; j < C; j++) { old_c = c; c = getchar(); while (c != '#' && c != '.') c = getchar(); line[j] = c; if (c == '#') { if (first_in_col) { if (j > 0 && last_line[j - 1] == '#') { printf("Bad placement.\n"); goto next; } if (last_line[j] == '#') is_new = 0; else is_new = 1; first_in_col = 0; if (is_new) ships++; continue; } if ((last_line[j] == '#') == is_new) { printf("Bad placement 2.\n"); goto next; } } else { first_in_col = 1; if (old_c == '#' && last_line[j] == '#') { printf("Bad placement.\n"); goto next; } } } #if 0 printf("line is: "); for (j = 0; j < C; j++) putchar(line[j]); putchar('\n'); #endif getchar(); // READ EOL swap_lines(&line, &last_line); } printf("There are %d ships.\n", ships); next: #if 0 printf("R = %d, C = %d\n", i, j); #endif for (; i < R; i++) { while(c != '\n') c = getchar(); c = '.'; } } return 0; }