Many of you would have seen a paper-and-pencil game in which a table of alphabets is presented. When one looks at this for the first time, it is likely that only a seemingly random set of alphabets are present. On close look, one can discern that there are meaningful words "hidden" along particular rows and columns. See if you can discover the word NIGHTLY tucked away in rows and columns.
R N I G H T L Y I Y
X I T W Q L Z N O V
A G Y B X M N U Y L
Q H N O T F V J K N
V T M I D O U Y R I
P L B X G G K I F G
R Y K F N H E N O H
V J F D K T T C M T
H D X Z W Q N L T L
V B C O K H F T Y Y
It is required to write a complete C program that takes a word maze as input from the user, and store this in an appropriate data structure. Then the user is given a word to be searched in the maze. The program must locate all occurrences of this word in the maze along Horizontal and Vertical directions.
Once the locations of the word are found in the maze, the program must also replace all other characters in the maze which are not part of the located words, by the 'space' character. The program must display the maze which now has only the locations and occurrences of the word searched for.
You are given an enum
typedef enum {
TOP = 0,
LEFT,
RIGHT,
BOTTOM,
} DIRECTION;
This enum represents different directions as the names suggests. The direction representation is as following:
TOP : from BOTTOM towards TOP
LEFT : from RIGHT towards LEFT
RIGHT : from LEFT towards RIGHT
BOTTOM : from TOP towards BOTTOM
You are required to write 2 functions:
1. void trimMaze(char maze[MAX_ORDER][MAX_ORDER], int orderOfMaze, char word[])
This function receives a two dimensional array maze and the orderOfMaze. Number of rows and columns in the maze are equal to the orderOfMaze. The function also receives the word which needs to be searched. You are required to locate all occurrences of the word that needs to be searched and replace all other characters with 'space' characters in the maze which are not part of the located words and store the result back in two dimensional array maze.
Example:
the maze is:
r a t a t
r s b c a
a e t a r
t b c d a
r a t w z
the word that needs to be searched is: "rat".
then after trim maze will be like:
r a t t
r a
a t a r
t
r a t
2. int getPositions(int positions[MAX_POSITIONS][NUM_OF_ATTRIBUTES], int posLength, char word[], char maze[MAX_ORDER][MAX_ORDER], int orderOfMaze, DIRECTION d, int r, int c)
This function receives a two dimensional positions array. In positions array every row represents a position of the word whereas columns represent the Indexes and directions of the word. In positions array first column represents the rowIndex of the word, second column represents the columnIndex of the word and third column represents DIRECTION in which word was found.
By Index we mean the array index of the word's starting letter.
Example:
If word ABC has indexes in array:
A: row- 0 col- 3
B: row- 0 col- 4
C: row- 0 col- 5
Then in positions array the first row will have
0 3 RIGHT
Note that the direction is RIGHT because the word was found while searching from LEFT towards RIGHT.
The function also receives length of the positions array which is posLength. As you find positions of the word you have to append those positions to the array positions and at the end you have to return the new length of the positions array.
The function also receives the word which needs to be searched, the maze in which you need to search the word, order of the maze, direction towards which you have to search the word.
The function also receives row index r and column index c which represents the row column indexes from which you have to start searching the word.
Example:
If parameters passed are
r = 1
c = 0
d = BOTTOM
order of maze = 10
then indexes you will search are:
(1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0),(9,0)