#K37177. Count Islands
Count Islands
Count Islands
You are given a grid map of size \(n \times m\) where each cell of the grid is either L
(land) or W
(water). An island is defined as a maximal group of connected land cells. Two cells are considered connected if they are adjacent horizontally or vertically (but not diagonally).
Your task is to compute the number of islands present in the grid.
Input Format:
- The first line contains two integers n and m representing the number of rows and columns of the grid.
- The following n lines each contain m characters (each being either
L
orW
) separated by spaces.
Output Format:
- Output a single integer that represents the number of islands in the grid.
Note: Use standard input (stdin) for reading input and standard output (stdout) for printing the result.
inputFormat
The first line contains two space-separated integers n and m.
Each of the next n lines contains m characters separated by a single space. Each character is either L
(land) or W
(water).
outputFormat
Output a single integer representing the number of islands.
## sample1 1
L
1