For Everyone
Given an array of strings in the form of a word search game, write a function:
int wordSearch(const char **tab, const char *word, int *indices);
That finds any occurance of 'word' in the table 'tab'. The function will return 0 if the word does not exist in the table and 1 if the word is found. The two-dimensional indices of the word will be placed in the array 'indices'. The list of indices will be terminated by an invalid index, -1.
Words can be found forward, backward, up, down, and diagonal in any direction. You may assume that all input will be correct and valid with the exception of a word not being present.
Example:
Given the following declarations:
Code:
char *tab[] = {
"abcde",
"bcdef",
"caefg",
"dtfgh",
"efghi",
""
};
int indices[11] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
the function call wordSearch(tab, "cat", indices); will return 1 and indices will contain the following: {1,1,2,1,3,1,-1,-1,-1,-1,-1}
Testing Categories
Code brevity. The smallest source file (in number of characters) with correct output wins.
Contest Ends: Wednesday, August 27, 2003