TopCoder problem "SimpleTextProcessor" used in TCHS07 Finals (Division I Level One)

Problem Statement


You are given a String[] words containing an even number of elements n. You want to place the words into two columns. The first n/2 elements of words must be placed in the first column, and the last n/2 elements of words must be in the second column. The order of the words in the input must be preserved. You are to return a String[] containing the words aligned into columns as described below.

The first element of the resulting String[] must contain the first elements of each of the two columns, the second element of the result must contain the second elements of both columns and so on. Each of the columns must be as narrow as possible; in other words, the width of each of the columns must be equal to the length of the longest word it contains. For each column, the width of each row must be the same (but the widths of the rows in the first and in the second columns may differ). If some words in a column are narrower than the width of the column, they must be padded with spaces. The words in the first column must be aligned to the left (so, all spaces will be added to the right side of words that require them), and the words in the second column must be aligned to the right. The columns must be separated by a single character column containing only '*'.



Method signature:String[] makeColumns(String[] words)
(be sure your method is public)


-words will contain between 2 and 50 elements, inclusive.
-words will contain an even number of elements.
-Each element of words will contain only lowercase letters ('a'-'z').
-Each element of words will contain between 1 and 20 characters, inclusive.


{"a", "b", "c", "d"}
Returns: {"a*c", "b*d" }
{"very", "exciting", "programming", "competition"}
Returns: {"very    *programming", "exciting*competition" }
{"simple", "test"}
Returns: {"simple*test" }
{"this", "software", "includes", "a", "number", "of", "subcomponents", "with",
"separate", "copyright", "notices", "and", "license", "terms"}
{"this         *     with",
"software     * separate",
"includes     *copyright",
"a            *  notices",
"number       *      and",
"of           *  license",
"subcomponents*    terms" }
{"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde", 
"abcdeabcdeabcdeabcde", "abcdeabcdeabcdeabcde"}
"abcdeabcdeabcdeabcde*abcdeabcdeabcdeabcde" }

Problem url:

Problem stats url:


Mike Mirzayanov


PabloGilberto , brett1479 , Olexiy , marian

Problem categories:

String Manipulation