File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wordfind

 
flim pc
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question pertains more to a c++ program than java.
I was wondering if anyone might be able to give me a hit as where to start. here is my issue. I am unsure how to start solving this problem. I thought about using recursion to search the matrix but i am kinda lost as how to start. I though i would begin by using the Knuth-Morris-Pratt string matching algorithm but just dont know where i should begin.

Input would be the Filename: wordfind.in

The input file consists of a square table and a list of words. A blank line follows the table and then the words to find, one per line.

This is a sample of what my file contains.

cenad
aatps
rnrpj
hello
wmneo

hello
apple
car
me
men
ran
woman

Output

Filename: wordfind.out

This is what I wish my program to do after the program is run:

hello (3, 0) E
apple (0, 3) S
car (0, 0) S
car (0, 0) SE
me (4, 1) N
men (4, 1) N
ran (2, 0) NE
woman NOT FOUND
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should search for the string one character at a time. For instance, if you are looking for "hello", then search for 'h'. Each time you find an 'h', search its surrounding characters for 'e'. Each time you find the 'e', continue matching the characters in that directions... 'l', 'l', and 'o'.
All loops end when a match of the full string is found.
 
flim pc
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might get something from this thread

http://www.coderanch.com/t/35083/Programming/June-Newsletter-Puzzle
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic