Problem D
Flow Layout
A flow layout manager takes rectangular objects and places them in a rectangular window from left to right. If there isn’t enough room in one row for an object, it is placed completely below all the objects in the first row at the left edge, where the order continues from left to right again. Given a set of rectangular dimensions and a maximum window width, you are to write a program that computes the dimensions of the final window after all the rectangles have been placed in it.
For example, given a window that can be at most 35 units
wide, and three rectangles with dimensions
The final dimensions of the resulting window are
Input
The input consists of one or more sets of data, followed by
a final line containing only the value 0. Each data set starts with a line containing
an integer,
Output
For each input set print the width of the resulting window, followed by a space, then the lowercase letter “x”, followed by a space, then the height of the resulting window.
Sample Input 1 | Sample Output 1 |
---|---|
35 10 5 20 12 8 13 -1 -1 25 10 5 20 13 3 12 -1 -1 15 5 17 5 17 5 17 7 9 7 20 2 10 -1 -1 0 |
30 x 25 23 x 18 15 x 47 |