Counting Stars
InterviewTime limit2sMemory limit1024 MB
Count the connected components of white pixels in a black-and-white bitmap, where adjacency is vertical or horizontal.
Problem
Astronomy has advanced greatly through the use of computer technology. Algorithms can automatically analyze digital images of the night sky and look for new patterns.
In this problem you write such an analysis program that counts the number of stars visible in a bitmap image. An image consists of pixels, and each pixel is either black or white. Black is written # and white is written -. Every black pixel is part of the sky, and every white pixel is part of a star. White pixels that are adjacent vertically or horizontally belong to the same star.
Input
Each test case begins with a line containing two integers 1 ≤ m, n ≤ 100. This is followed by m lines, each of which contains exactly n pixels.
Output
For each test case, print the case number followed by the number of stars visible in the corresponding image. Follow the format shown in the example below.