7 Replies Latest reply: Feb 26, 2009 3:36 AM by 807588

can anyone help me? we just got this problem in java programming and i'm kinda stuck. i can only do up to the reading of the .txt file using BufferedReader.

"Write a program that reads from an input file an M by N grid of letters and a list, L, of words, and, for each word, W, in L, finds the row, R, and column, C, in the grid where the word is found."

i'm not asking for an entire code..... i just want to ask HOW it is done, especially the diagonal words.

example:
input:
8 12
abcDEFGhiggx
hEbkWalDorkT
FtyAwaldORmr
FtsimrLqsrcE
byoArBeDeyvb
KlcbqwikomkG
yUiqlxcnBjfD
4
Waldorf
Bambi
Betty
Dagbert

output:
Waldorf 2 5
Bambi 2 3
Betty 1 2
Dagbert 7 8
This isn't very complex task once you think it the way you solve a crossword puzzles in real world.

Once you have the grid of letters and list of words you could start the search by taking the first letter of a word and try to locate it from the grid. When you find it just check if the second letter would be the next at the same line and the third the next after the next and so on. That's for horizontals, for verticals do the same but instead of next check the letter below. For diagonals check the letter one forward and one down.
maybe read it into a two dimensional array, then you can easily find a letter by column and row number, then you can use the index where you find the first letter to check the 8 surrounding it, just make sure to catch ArrayIndexOutOfBoundsException if where you found the first letter is on the edge or something
i....... uhhh................. kinda don't know how to do that......
faye159 wrote:
i....... uhhh................. kinda don't know how to do that......
Do you know arrays?

If not, then go [learn about them|http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html].