HTML Table

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

      The company Kozilla is developing the new browser Waterrat. Your task is to develop the part of the browser responsible for rendering tables.
      In this problem we will consider the simplified version of HTML. We will only consider the part of HTML that describes tables. HTML document is the sequence of opening and closing tags. The contents of HTML document is located between the tags.
      The opening tag is specified as <tag-name attributes>, the closing tag — </tag-name >. Here attributes mean the sequence of name ="value " descriptions. Attributes are used to specify various properties of web-page elements. Table is a set of cells ordered by rows and columns. Tags <table> and </table> are used to specify a table. The description of the table is between the tags.
      The description of the table is the sequence of the descriptions of table rows. Row description is located between <tr> and </tr> tags and consists of a sequence of cell descriptions. Cell description consists of a <td> — </td> tag pair, the contents of the cell is located between these tags.
      Let us consider an example of a table and the way it is displayed in a browser.

<table>
<TR><td>1</td><td>2</td></TR>
<TR><td>3</td></TR>
<TR><td>4</td><td>5</td><td>6</td></TR>
</table>

      You must have noticed that some cells may be absent, and tag names are not case sensitive. 
      To draw more complicated tables, one can specify a table cell that would occupy more than one row and/or column. To do so, one must add attributes rowspan="R" and/or colspan="C" to the <td> tag. Such cells expand down to span R rows and to the right to span C columns.
      The table is rendered row after row. When creating a row, and the new cell description is considered, the first free position in the row is selected. Let the cell being rendered occupy C columns. If there are C successive free positions in a row, starting from the selected one, the cell occupies these positions (and spans down to the required number of rows). In the other case the table description is considered erroneous. The behaivour of the browser in this case is not specified, your routine must report error.
      Let us consider two more examples.

<table>
<tr>
<td>1</td>
<td rowspan="2">2</td>
</tr>
<tr>
<td colspan="2">3</td>
</tr>
</table>

<table>
<tr>
<td colspan="3">1</td>
<td rowspan="2" colspan="2">2</td>
</tr>
<tr>
<td colspan="2">3</td>
<td>4</td>
<td rowspan="2">5</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
<td rowspan="2">8</td>
<td rowspan="2">9</td>
</tr>
<tr>
<td colspan="2" rowspan="2">0</td>
</tr>
</table>

      Given a table description, you must print the outlines of the table to the output file. You must ignore the contents of the cells, all cells must contain only spaces.

 

Input

      The input file contains a web-page fragment that describes the table. It is guaranteed that the description is correct and describes exactly one table. The input file contains only <table>, </table>, <tr>, </tr>, <td> and </td> tags. Only <td> tags have attributes, only rowspan and colspan attributes are used.
      Tag and attribute names are case insensitive. The values of rowspan and colspan attributes are positive integer numbers not exceeding 10.
      The table describes at least one row, each row description contains the description of at least one cell. 
      The contents of the cell is specified between <td> and </td> tags and may contain arbitrary text, containing characters with ASCII codes from 33 to 126 except ‘<’, as well as spaces and line breaks.
      Spaces and line breaks may occur between any tags; inside tags between the tag name and the attribute name, between the tag name and the ‘>’ character, between the attribute name and the ‘=’ character, between the ‘=’ character and the ‘"’ character before the attribute value, between the ‘"’ character after the attribute value and the following attribute name, between the ‘"’ character after the last attribute value and the ‘>’ character. They must be ignored.
      It is guaranteed that the table described contains at most 100 cells, the size of the input file does not exceed 10 kilobytes.

Output

      Print the outline of the table to the output file.
      Use the following characters:
‘+’ (plus) — to display line intersections;
‘|’ (vertical line, ASCII code 124) — to display vertical lines;
‘-’ (minus) — to display horizontal lines;
‘ ’ (space) — in all other cases;
      The cell that occupies m rows and n columns must be displayed as 2m − 1 rows of 2n − 1 spaces. If the table is erroneous, print “ERROR” to the output file.

Sample Input

<table>
<TR><td>1</td><td>2</td></TR>
<TR><td>3</td></TR>
<TR><td>4</td><td>5</td><td>6</td></TR>
</table>
<table>
<tr>
<td>1</td>
<td rowspan="2">2</td>
</tr>
<tr>
<td colspan="2">3</td>
</tr>
</table>
<table>
<tr>
<td colspan="3">1</td>
<td rowspan="2" colspan="2">2</td>
</tr>
<tr>
<td colspan="2">3</td>
<td>4</td>
<td rowspan="2">5</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr>
<td>7</td>
</tr>
<tr>
<td rowspan="2">8</td>
<td rowspan="2">9</td>
</tr>
<tr>
<td colspan="2" rowspan="2">0</td>
</tr>
</table>

Sample Output

+-+-+
| | |
+-+-+
| |
+-+-+-+
| | | |
+-+-+-+
ERROR
+-----+---+
|     |   |
+---+-+   +-+
|   | |   | |
+-+-+-+---+ |
| |       | |
+-+       +-+
| |
+-+-+
| | |
| | +---+
| | |   |
+-+-+   |
    |   |
    +---+

Hint

单组数据,样例为3组数据

Source

Andrew Stankevich Contest 16

Manager

Information
Solved Number14
Submit Number53
Problem Tags
No tag edit access
温馨提示:AC后可以编辑标签哦. ^-^
Login
LoginCancel