programming problem
- From: greg <gregfoto@xxxxxxxxx>
- Date: Mon, 19 May 2008 15:39:40 -0700 (PDT)
Write a program that reads a file containing a sorted list of
words (one word per line, no spaces, all lower case), then identifies
the
longest word in the file that can be constructed by concatenating
copies of
shorter words also found in the file.
For example, if the file contained:
cat
cats
catsdogcats
catxdogcatsrat
dog
dogcatsdog
hippopotamuses
rat
ratcatdogcat
The answer would be 'ratcatdogcat' - at 12 letters, it is the longest
word made up of other words in the list.
I'm having trouble coming up with anything other than starting with
the longest word in the list and checking for each of the other words
in the list, which seems incredibly inefficient, any ideas or
suggestions of things to look at?
.
- Follow-Ups:
- Re: programming problem
- From: cbcurl
- Re: programming problem
- From: Bart
- Re: programming problem
- Prev by Date: Call Accounting Software and icecream/brownies
- Next by Date: Re: The spinoza papers: towards a theory of progress reporting
- Previous by thread: Call Accounting Software and icecream/brownies
- Next by thread: Re: programming problem
- Index(es):
Relevant Pages
|