SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 386.8k

recursion help ??

Oct 25 2013 1:43 AM
Hi everyone 

I am stuck i donno were to start how to deal .. please look at the below requirement doc 

Write a recursive method that counts the number of creatures on a grid. An creature is defined as a contiguous collection of 1's (connected horizontally and vertically).



Input


Max dimensions of the array


Distribution of organisms on the array



Output


The number of creatures and the layout of the grid showing the locations of the creatures.


Requirements checklist:


q Documented source code (include any assumptions you make)


Input File (in.txt)


The format of the input file is as follows: First line is the dimensions of the grid.. Then the grid containing 1s for the creatures and 0s for the spaces. The file terminates by 0 0.




5 5


0 0 0 0 0


0 1 1 1 0


0 0 0 0 0


0 0 0 0 0


0 0 0 0 0


5 5


0 0 0 0 1


0 1 1 1 0


1 0 0 0 0


0 0 0 0 0


0 0 0 0 0


0 0




Output File (out.txt)


Experiment # 1


Number of Creatures: 1


0 0 0 0 0


0 1 1 1 0


0 0 0 0 0


0 0 0 0 0


0 0 0 0 0




Experiment #2


Number of Creatures: 3


0 0 0 0 1


0 2 2 2 0


3 0 0 0 0


0 0 0 0 0


0 0 0 0 0


Cheers & best wishes 
Thank you 

Answers (6)