A listing of names can be arranged in rows and columns to make it compact.
We want our listing to be arranged alphabetically in column major order (e.g. the
first column should have all the earliest words in the list). Words
should be left justified within their column. Each column has a fixed width, which may differ
from the width of other columns.
Each
row should have a name in each column, except the last row, which may have
no names in its final column(s).
Our list will be printed out row by row, with spaces inserted to position the names
within each row properly.
Each row must contain exactly pageWidth characters (including spaces).
In order to avoid run-together, we require that only
spaces can appear in the print position just prior to the start of a column. This applies even
to the last row (where the final columns may contain no names).
Create a class Lister that contains a method doList that is given
pageWidth and a String[] names and that returns the optimal listing
as a String[] giving the rows to be printed (in order from top to bottom). Each
element in the return should contain
exactly pageWidth characters. Use the space character ' ' in your listing
to position the names within each row (and to pad each row to pageWidth characters).
A listing is "optimal" if it has as few rows as possible. Among listings with
the minimal number of rows, choose the one whose rightmost non-space character is
as far to the left as possible. If multiple listings are still equally "optimal" choose the one with the fewest columns.
|