#include #include char line[1100]; char line2[1100]; char tecky[] = "..............................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." "..............................................................................." ; int lode; void OneTask(int R, int S) { lode = 0; bool ok = true; scanf("%s", line); for(int i = 1; i < R+1; i++) { if(i < R) scanf("%s", line2); else strcpy(line2, tecky); //printf("--- %d\n", i); if (!ok) continue; for(int j = 0; j < S; j++) { if (line[j] == '#') { // test levyho rohu if (j > 0 && line2[j-1] == '#') { ok = false; break; } bool nic = true; bool all = true; while (j < S && line[j] == '#') { if (line2[j] == '#') nic = false; else all = false; //printf("%d: %d, %d\n", j, line[j], line2[j]); j++; } // test pr. rohu if (j < S && line2[j] == '#') { ok = false; break; } if (!all && !nic) ok = false; else { if (nic) lode++; //printf("LOD %d %d\n", nic, all); } } } strcpy(line, line2); } if(!ok) printf("Bad placement.\n"); else printf("There are %d ships.\n", lode); } int main() { int x, y; for(;;) { scanf("%d %d", &x, &y); if ((x == 0) && (y == 0)) { break; } OneTask(x, y); } }