10. |
P7. Two-dimensional Arrays
Arrays store a linear arrangement of values, accessed by a single index. Two-dimensional arrays or matrices store a tabular arrangement of values, accessed by two indexes, for example matrix[i][j], where i is the row index, and j is the column index. Crosswords are a type of puzzle where the "pieces" of the puzzle have letters in common. For example, these pieces share the letter 'o'.
d across w n
Write a program that will accept a list of words into an array list of strings, then make a 20 x 20 array of char that contains a crossword puzzle with these words.
For example, when given the list addle, apple, clowning, incline, plan, burr your program should display:
addle p p clowning e n c l i plan e You may want to use the following method: Place the first word horizontally in the center of the grid. Place the next word vertically. Check if there is a common letter already on the grid, and if all the squares into which you want to place that word are still empty. (If you can't place it on any of the common letters, skip the word.) Then switch back to horizontal, place the next word if possible, and so on.
Answer:
|