CS 141 - Lab 1

Word Search

Directions

Find a partner. Solve the following programming problem in C++. When you finish, turn it in electronically, one copy per team. When you are done, you should work on Homework 1 or Programming Assignment 1.

Overview

Given a grid of letters up to 50x50, find where in the grid a given word occurs. Each word is guaranteed to occur at least once. Matching may be done forward or backward, horizontally, vertically, or diagonally (8 cases total.)

Input Spec

Read in a single integer: this is the number of cases (grids) you will do on this run of the program. (1 int)

For each case, read in the number of lines (m) and the number of columns (n). (2 ints)

For each row, read in each character. (m repetitions of reading n characters).

Read in the number of words that will be found in the grid (w). (1 int)

Read in those words (w strings)

Continue with the next case.

Output Spec

Your output must match exactly the following, including whitespace.

For each word, print out the row and column of the starting letter in that word. In case there is more than one instance of that word in the grid, break ties first with lower row numbers, then with lower column numbers.

Testing

Test cases can be found here. Run these using regular UNIX redirection & testing:
./lab1 < inputFile | diff - outputFile
Where inputFile and outputFile will be one of these or a pair of your own creation.
lab1test1.in lab1test1.out
lab1test2.in lab1test2.out
If the testing line above produces no output when run with these tests, then you have completed the program.

Recommended Approach