Class name: CrosswordPuzzle
Method name: getAnswer
Parameters: String[], int
Returns: String
Write a class CrosswordPuzzle that contains a method getAnswer which returns
the word at a given location in the puzzle.
A crossword puzzle is a grid of white squares and black squares. White squares
get filled in with letters; black squares represent
word boundaries. Each word in the crossword puzzle runs either horizontally
(left to right) or vertically (top to bottom). Words will never appear
backwards (right to left or bottom to top). Each word is also numbered, based
on the square where it starts, in the following manner:
Start at the top left corner of the grid. Proceed right across the row, then
go left to right across the next row, etc. When a square is encountered that
starts a word, it is assigned the next integer -- integers start at 1.
Of particular note:
-- A list of all the horizontal words in the puzzle will not necessarily
contain all of the numbers in the puzzle.
-- The same goes for the vertical words.
-- One horizontal word and one vertical word may share the same number.
getAnswer takes two arguments: String[], with each String representing one row
of the crossword; and an integer representing the number of the sought-for
word. It returns a String - either the sought-for word or "not found" if the
specified number doesn't exist in the puzzle.
The number will be positive if a horizontal word is desired and negative if a
vertical word is desired. Thus, if wordNum==4, you should return the
horizontal word given at number 4 or "not found"; if wordNum==-10, you should
return the vertical word given at the number 10 or "not found".
The method signature is:
public String getAnswer (String[] puzzle, int wordNum) (be sure your method is
declared public)
Notes:
-- puzzle has between 3 and 21 elements, inclusive. The elements contain only
capital letters ('A'-'Z', inclusive) and asterisks ('*'). (TopCoder will check
this.)
-- Each element of puzzle array represents a row which corresponds to a row of
the crossword puzzle given in sequential order. For example, puzzle[0]
corresponds to the first row of the crossword puzzle, puzzle[1] corresponds to
the second row of the crossword puzzle ... puzzle[N] corresponds to the N+1 row
of the crossword puzzle. The 0th character of each of the elements is the
leftmost character of the row.
-- Asterisks represent the black squares in the puzzle and are word boundaries.
-- Each element of puzzle must have the same length, which must be the same as
the number of elements in the array - in other words, the puzzle is square.
(TopCoder will check this.)
-- Each word in a crossword puzzle must be at least two characters in length.
-- All characters will be part of at least one word. In other words, there
will be no letter that is surrounded on all four sides by black squares or the
border. (TopCoder will check this.)
-- wordNum must not be equal to zero. (TopCoder will check this.)
-- BOXES WHICH DO NOT START WORDS ARE NOT NUMBERED.
EXAMPLES:
Given a puzzle: HAT 1*2
E*O --> ***
RUN 3**
wordNum==1 returns "HAT"
wordNum==-1 returns "HER"
wordNum==2 returns "not found"
wordNum==-2 returns "TON"
wordNum==3 returns "RUN"
Anything else returns "not found"
Given the puzzle: TRITE 123*4
HOT*X 5****
EL*HI --> 6**7*
*EMIT *89**
AXE*S 10****
wordNum==1 returns "TRITE"
wordNum==5 returns "HOT"
wordNum==6 returns "EL"
wordNum==7 returns "HI"
wordNum==8 returns "EMIT"
wordNum==10 returns "AXE"
wordNum==-1 returns "THE"
wordNum==-2 returns "ROLEX"
wordNum==-3 returns "IT"
wordNum==-4 returns "EXITS"
wordNum==-7 returns "HI"
wordNum==-9 returns "ME"
Anything else returns "not found"