Input File: cartin.txt
Output File: cartout.txt
Time Limit: 0.125 seconds
Once again you are a surveyor in the Pacific, ready to report to the Queen of Australia with facts and statistics about her offshore colonies. Last night whilst playing bridge with the Earl of Wessex she bet a castle over the size of the British Empire, and they all look to you for an answer. Your task is to discover just how much land the Queen actually owns.
In the old-fashioned way you board your surveying ship and sail around the coast of each island, marking the locations of the beaches. Back in your office you examine the various coastlines and set yourself the task of working out the area of each island.
Each input file will contain a single island, represented on a rectangular map of size w by h (1 <= w,h <= 100). The first line of input will be of the form w h. Following this will be h lines, each w characters long, representing a map.
The map will be composed entirely of periods (
#). Every square of ocean will be marked with a period.
Every square of island that is inland (does not touch the
ocean on an edge or a corner) will also be marked with a period.
Every square of island that contains beach (touches the ocean on
either an edge or a corner) will be marked
You are guaranteed that there is at least one
# on the map,
that there is only one island and that this island contains no lakes
(inland beaches). You may assume that the world is flat.
The output must be a single line containing the area (in squares) of the entire island. This area is the number of beach squares plus the number of inland squares.
7 6 ....... ..###.. .##.##. ..#..#. ..####. .......
In the map above, there are 13 beach squares and 3 inland squares giving a total area of 16.
The score for each input file will be 100% if the correct answer is written to the output file and 0% otherwise.