eolymp
bolt
Try our new interface for solving problems
Problems

Tables

Tables

HTML uses a simple tag format for table layout. You are to create ASCII-art tables based on a simplified notation. Logically, a table can be considered an \textbf{m} by \textbf{n} grid, each with a \textbf{2}-character wide by \textbf{1}-character high cell, for example a \textbf{2}×\textbf{3} grid would be as follows: \includegraphics{https://static.e-olymp.com/content/a9/a987b371790880fe37f3680bdf29284edcace102.jpg} The output consists of \textbf{2m+1} rows, each having \textbf{3n+1} characters (including leading and trailing spaces in odd-numbered rows). But some tables are not strictly grid-based, because the values for certain cells can span multiple rows and/or columns. Here is the layout if cell \textbf{11} has a row span of \textbf{2} and cell \textbf{22} has a column span of \textbf{2}: \includegraphics{https://static.e-olymp.com/content/da/dad97658729cce1fd49a2e9ebeadee25705f95c8.jpg} You are to create these ASCII-art tables given \textbf{m}, and the row span and column span values. \InputFile The input consists of multiple test cases. The first line of each test case contains one integer \textbf{m}, the number of rows. Then, \textbf{m} lines follow, describing the row and column spans in the layout. Each of the next \textbf{m} lines gives the span information for a row. The span information is given only for the upper left cell in the span. If \textbf{N} row spans and column spans need to be specified for a given row, these would be specified as: \textbf{N RS_1 CS_1 ... RS_N CS_N} where the values \textbf{RS_k} and \textbf{CS_k} are between \textbf{1} and \textbf{9}, and specify how many rows and columns the next cell needing information in this row needs to occupy. Previous row spans or column spans may imply that fewer cells than the total number of columns need to be specified for a particular row. You may assume that the input is valid: \begin{itemize} \item the number of rows and columns are between \textbf{1} and \textbf{9}; \item every row will have the same number of columns; \item there are no overlapping spans of cells; \item every cell is contained in some span of cells. \end{itemize} There are at most \textbf{100} test cases and the end of input is indicated by \textbf{m = 0}. \OutputFile For each case, display the ASCII-art table, with the row-column index displayed in the top left corner of every span of cells. Display a blank line after every case.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
3
2 1 1 1 1
2 1 1 1 1
2 1 1 1 1
3
2 1 1 2 1
1 1 1
2 1 1 1 1
3
1 1 2
2 1 1 1 1
2 1 1 1 1
3
2 2 1 1 2
1 2 2
1 1 1
0
Output example #1
 -- --
|11|12|
 -- --
|21|22|
 -- --
|31|32|
 -- --

 -- --
|11|12|
 --
|21|  |
 -- --
|31|32|
 -- --

 -- --
|11   |
 -- --
|21|22|
 -- --
|31|32|
 -- --

 -- -- --
|11|12   |
    -- --
|  |22   |
 --
|31|     |
 -- -- --
Source 2013 Rocky Mountain Regional ACM Contest