I need to write a recursive Java program to count the number of muck-free regions in a lagoon. The Lagoon is represented by a rectangle of N x M squares. Each square contains either muck ('M') or sand ('.'). A region is defined as a connected set of one of more squares with sand in it, where a square is considered to connect to all eight of its adjacent squares. Sample input/output is shown in picture attached

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 7PP: (Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point...
icon
Related questions
Question
100%

I need to write a recursive Java program to count the number of muck-free regions in a lagoon. The Lagoon is represented by a rectangle of N x M squares. Each square contains either muck ('M') or sand ('.'). A region is defined as a connected set of one of more squares with sand in it, where a square is considered to connect to all eight of its adjacent squares. Sample input/output is shown in picture attached

Input Format
The first line consists of two space-separated integers: N and M (1 <= N<= 100; 1 <= M <=
100). The remaining N lines consist of M characters each. Each character is either 'M' or '.'
representing one square in IRL. The characters do not have spaces between them.
SAMPLE INPUT
10 12
. MMMMMMMM..M
М...МММММ...
MMMM..MMM..M
МMМMMMMMM..М
МMMMMMMMM.MМ
MM. MMMMMM. MM
М.М.МММMM..М
.М.М.МММММ.М
М.М.МMMMMМ.М
MM. MMMMMMM.M
SAMPLE OUTPUT
The number of muck free spots in the input:
3
One spot is in the upper left, one down the right side, and the third one is spread out n the
lower left corner.
Transcribed Image Text:Input Format The first line consists of two space-separated integers: N and M (1 <= N<= 100; 1 <= M <= 100). The remaining N lines consist of M characters each. Each character is either 'M' or '.' representing one square in IRL. The characters do not have spaces between them. SAMPLE INPUT 10 12 . MMMMMMMM..M М...МММММ... MMMM..MMM..M МMМMMMMMM..М МMMMMMMMM.MМ MM. MMMMMM. MM М.М.МММMM..М .М.М.МММММ.М М.М.МMMMMМ.М MM. MMMMMMM.M SAMPLE OUTPUT The number of muck free spots in the input: 3 One spot is in the upper left, one down the right side, and the third one is spread out n the lower left corner.
Expert Solution
Step 1

Attaching the code with screen shot

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning