Count the Lakes
The map has land (L) and water (W). Water cells touching side-by-side (not diagonally) form one lake. Count the lakes.
Input: the first line has N and M; the next N lines each have M characters.
Output: the number of lakes.
Constraints:
- 1 ≤ N, M ≤ 500
Sample Tests
Input 1
3 4 LWWL LLWL WLLL
Output 1
2
Input 2
1 1 L
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.