Your first task, as with any program, is to break it down into discrete steps. This is an iterative process, meaning that you start with a single step -- "solve the problem" -- and break that step into smaller steps. You then
recursively break those steps into smaller steps, and so on until all of the steps are "sufficiently small." Defining this latter term comes with experience.
One first cut at breaking it apart might be
Read the input file into a data structure.Find all of the contiguous blocks.Write the complete solution to the screen of file (whatever assignment says). Clearly, these are still pertty big steps. You'll need to think about how to break it down further. Instead of having us do it for you, which will teach you nothing, try it out yourself and post what you can get. I'm sure you have
some ideas about this, so let's have 'em!
Now, you don't necessarily have to break all the steps down into detail before you start. This is key! If you start by working on the first step, you can ignore the other two for now. I'd even recommend that you do #1 and #3 before attempting #2 for the simple reason that without #3 you won't know when you have #2 working.*
[ * True, you could write up an algorithm to programmatically
test your solution, but I think that's a bit beyond the beginner level. ]
[ February 03, 2005: Message edited by: David Harkness ]