Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help creating a word finder in JAVA. The program should allow the user to input AxB matrix of characters and a string word.

I need help creating a word finder in JAVA. The program should allow the user to input AxB matrix of characters and a string word. The program should be able to find the word in the given matrix. The following rules apply:
1. The word can be formed in any direction (forward, backwards, forwards diagonal, backward diagonal, etc.)
2. The same letter cant be reused to form the word
3. Must follow any of the above directions with their combination while forming the words.
Input Format (Your code must read from standard input (no file I/o is allowed))
The first line of the input consists of 3 integers, A, B, and C. Here A = number of rows in the matrix, B = number of columns in the matrix, and C = number of words you need to find from this matrix. Then A lines represent the rows input characters, where each line has B characters separated by space. After A lines, there will be C lines of words. You need to find these words in the matrix. Similarly, D test cases will be provided in the above format. The program should use a backtracking strategy. Hint : Have a wrapper function. From the wrapper function, call the back tracking worker function for each box in the matrix until you find a solution or you decide there is no solution.
Sample input1:
346
C B A B
B N O D
M D E E
ABC
BAOED
CNE
NEC
NEED
NEEDON
Output Format
Sample output1 for input 1
Looking for ABC
[C, B, A,]
[,,,]
[,,,]
Looking for BAOED
[, B, A,]
[,, O,]
[, D, E,]
Looking for CNE
[C,,,]
[, N,,]
[,, E,]
Looking for NEC
NEC not found!
Sample input2:
444
c o m p
a m a p
a p s s
x y z q
mop
comp
omo
maa
Sample output2
Looking for mop
mop not found!
Looking for comp
[c, o, m, p]
[,,,]
[,,,]
[,,,]
Looking for omo
omo not found!
Looking for maa
[,,,]
[a, m,,]
[a,,,]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions