Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given an m by n grid of letters, and a list of words, find the location in the g

ID: 3641448 • Letter: G

Question

Given an m by n grid of letters, and a list of words, find the location in the grid where the word can be found. A word matches a straight, contiguous line of letters in the grid. The match could either be done horizontally (left or right), vertically (up or down) or diagonally (from bottom right to upper left or bottom left to upper right)

The input will be in a file called hidden.txt and your output will be written to a file called found.txt. The format of the input file will be as follows:

First line will have two integers - m, the number of lines in the grid and n, the number of characters in each line. The integers m and n will be separated by one or more spaces.
There will be a single blank line.
There will be m lines, where each line will have n characters, all in upper case, separated by a space.
There will be a single blank line.
There will be a single integer k, denoting the number of words that follow.
There will be k lines. Each line will contain a single word in all uppercase.

There will be k lines in your output file. Each line will have the word that you were search for followed by two integers i and j separated by one or more spaces. The numbers will be right justified and aligned. The number i gives the row and the number j the column of the first letter of the word that you were required to find. Rows and columns are numbered conventionally, i.e. the first row is 1 and the first column is 1. If you do not find a word in the grid then the values for i and j will be 0 and 0.
--------------------------------------------------------------------------------------------------------

The file hidden.txt is as follows:


14 14

S I N S N O W S T O R M W I
K L N T S N O W M A N E F E
A R E C A L P E R I F R I E
T C G I C A N D L E E R M K
E F H B G T A O C E E Y I A
S R R I L H T U Z P A C T L
T A N O L I B E R I G H T F
B C D H S L Z E T A N R E W
O S D E E T T Z L D R I N O
O E D V L N I S A L S S S N
T B O L I S C Y Y R S T E S
S H H W O L E L O W D M C A
S N A D E C E M B E R A D L
E L T I S E A S O N G S H T

14
BLIZZARD
BOOTS
CANDLE
COAT
DECEMBER
FIREPLACE
HILL
MITTENS
SEASON
SKATES
SLEIGHBELLS
SNOWMAN
SNOWSTORM
WINTER

--------------------------------------------------------------------------------------------------------

The file found.txt is as follows:

BLIZZARD 5 4
BOOTS 8 1
CANDLE 4 5
COAT 5 9
DECEMBER 13 4
FIREPLACE 3 11
HILL 5 3
MITTENS 4 13
SEASON 14 5
SKATES 1 1
SLEIGHBELLS 1 1
SNOWMAN 2 5
SNOWSTORM 1 4
WINTER 12 4

-------------------------------------------------------------------------------------------------------

I started but got stuck and this is all I have...not sure if I was going in the right direction:

import java.util.*;
import java.io.FileReader;
import java.io.FileNotFoundException;

public class WordSearch
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner sc = new Scanenr(new FileReader("hidden.txt"));
int[][] grid = new int[m][n]

for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
grid[i][j] = sc.nextInt;
}
}


}

}

Explanation / Answer

Indent this code first before running. #include using namespace std; int main(){ for(;;){ int m,n,i,j; cin>>m>>n; if(m==0 && n==0) break; char ch[m][n]; for(i=0;ic; ch[i][j]=tolower(c); } } int test; cin>>test; while(test--){ string str; cin>>str; int ctr=0; for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote