Problem D |
Freedom Fighter |
Time Limit |
5 Seconds |
In the figure the area bordered by a rectangle indicates a sector. In the input to your program a sector may contain any of the three characters ‘*’, ‘B’, ‘P’. Here B indicates the locations where there are some freedom fighters, P indicates the places occupied by enemy forces and the locations occupied by none of them are identified by some *. In a sector all the B, P or * are connected either horizontally or vertically. Within a sector there may be one or more freedom fighter group or enemy group. Each of the freedom fighter groups will be identified by some B connected to another vertically or horizontally. Similarly enemy groups will be identified by the character P. No two sectors will have a connection either horizontally or vertically. There may be some . (dots) to separate two sectors. In the above picture we can see that there are two (2) groups in a sector. If a group is horizontally or vertically connected to an opponent group then this two groups are said to be in fighting position. It is granted that a freedom fighter group can fight only one opponent group at a time.
Input
There will be several test cases. The
input of each test case starts with a single integer n (5 ≤ n
≤ 50). A 0 for the value of n indicates the end of input. The
next n lines consist of a description of n x n grid. Each line
will have n characters which will be either of . , * , B
and P.
Output
For each set of input, output as many
lines as the number of sectors detailing the number of freedom fighter groups
and enemy groups. The last line of the input will indicate how many groups are
in fighting position. The sectors are numbered according to the position of the
top left corner in row major order. Print a blank line after each test case. For
exact format of input and output see the sample output below.
Sample Input |
16 ................ ................ .******......... .**PP**....***.. .******....*B*.. .******....***.. .**BB**......... .******......... ................ .....*******.... ....*BB**BB**... ....*BB**PP**... ....*********... ....****PP***... .....*******.... ................ 0 |
Output for Sample Input |
Sector #1: contain 1 freedom fighter group(s) & 1 enemy group(s) Sector #2: contain 1 freedom fighter group(s) & 0 enemy group(s) Sector #3: contain 2 freedom fighter group(s) & 2 enemy group(s) Total 2 group(s) are in fighting position. |
Problemsetter:
S. A. M. Harun
International
Islamic University