Table Rendering
InterviewTime limit2sMemory limit1024 MB
Given per-row cell widths, draw an ASCII table where each horizontal separator has a '+' exactly under or over every vertical bar.
- Level
Medium4 of 10
- Topics
- Implementation, Simulation, Array, String
- Solved
- No attempts yet
Problem
When developing programs for viewing web pages, one of the most difficult tasks is rendering tables correctly. The company <<Kozilla>>, where you work, plans to develop a new version of the <<Waterrat>> browser for terminal mode and asks you to write the fragment of the web page rendering core responsible for building the structure of tables.
The fragment you must write receives information about the number of rows of a table and the cells of those rows, and must generate the table structure and pass it to the module that renders the table on screen.
A table consists of rows, each row consists of one or more cells, and the -th cell of the -th row has width .
Given the parameters of the table, construct a symbolic image of its structure.
Input
The first line of the input file contains , the number of rows in the table (). The next lines of the input file contain descriptions of the table rows.
The description of each row includes the number , the number of cells in that row, and integers , the width of each cell in the row (, ).
Output
Output a symbolic image of the table structure to the output file.
The image of the -th row of the table must begin with an image of a horizontal line made up of the characters <<+>> (plus) and <<->> (minus). Then a line containing spaces and <<|>> (vertical bar) characters must follow. The first character of the line must be a vertical bar, then spaces, then a vertical bar, then spaces, and so on, for a total of blocks of spaces. After the last block a vertical bar must follow. After the last row of the table, an image of a horizontal line must also follow.
In the image of a horizontal line, use the character <<+>> if a vertical bar is above or below that position, and <<->> otherwise. The horizontal line must have the minimum possible length so that there are <<+>> characters above every vertical bar character of the next line and below every vertical bar character of the previous line.