#P5962. Ship Tonnage Counting
Ship Tonnage Counting
Ship Tonnage Counting
You are given an grid representing a board for a ship game. Each cell is either black (denoted by 'B', representing a part of a ship) or empty (denoted by '.'). Two black cells that share a common edge belong to the same ship. Different ships do not touch each other along their sides. The tonnage of a ship is defined as the number of connected black cells.
For example, in the sample illustration, the board contains one -ton ship, three -ton ships, two -ton ships, and three -ton ships. Your task is to determine the tonnage and the number of ships corresponding to that tonnage for a given board.
inputFormat
The first line contains an integer (), representing the size of the board. The next lines each contain exactly characters. Each character is either 'B' (indicating a black cell, part of a ship) or '.' (indicating an empty cell).
outputFormat
For each unique ship tonnage, output a line with two space-separated integers: the tonnage and the number of ships with that tonnage. The output should be sorted in descending order of tonnage.
sample
3
B..
.B.
..B
1 3