DWITE Online Computer Programming Contest

Floor Plan

November 2007
Problem 3

A common way to value a house, among other things, is by the area of the rooms. Though, it could be less than trivial to accurately calculate the area of a room that is not in a standard shape. Given a floor plan diagram, with rooms of interest marked, their areas should be calculated.

The input file DATA3.txt will contain two lines with one integer value each, R, C; 0 < R, C ≤ 40, representing the number of rows and columns that make up the floor plan. This is followed by R lines showing the floor plan layout, where:

The output file OUT3.txt will contain 5 lines. Each line will have an integer representing the area of a room of interest. The first line should contain the area of room 1, second line for room 2, etc.

The area of the room is defined as 1 + number of reachable open spaces. The integer marker could appear anywhere inside the room.

Sample Input:
5
6
1###..
##4#5.
2#####
.#.#..
...#.3
Sample Output:
1
6
4
1
4