Problem E

What be thy Name, O Dear Tree?

Input: Standard Input

Output: Standard Output

 

Sir Jagadish Chandra Bose (November 30, 1858 – November 23, 1937) was a Bengali physicist and science fiction writer, is considered the father of radio science. He made remarkable progress in his research of remote wireless signaling as well as in plant physiology. Sir Bose scientifically proved parallelism between animal and plant tissues using his own invention crescograph to measure plant response to various stimuli. His experiments showed that plants grow faster in pleasant music and its growth retards in noise or harsh sound. [ courtesy : www.wikipedia.org ]

 

Our hero little Dablu (his actual name is Bablu, see “Shahnaj o Captain Dablu” by Dr. Md. Zafar Iqbal) is conducting some experiments on plants. As demonstrated by Sir J.C. Bose, Dablu is upto observing the influence of music on plants growth. He plays a certain tune to a certain plant for elongated period of time and takes snapshots of the plant in regular intervals. Dablu does not believe in uprooting a plant completely or yanking a branch of the plant for so called ‘speciment collection’ purpose, plants are also living beings, after all. Instead, he would take a picture of the plant, convert this picture into a string to represent the plant according to a L-System grammer defined by himself. The string will be stored into his PDA along with time-stamp and other meta-data. Upon returning to his lab, he would download the snapshots (L-System strings) from his PDA into his computer. Then he will use a program written by you to reconstruct the plant pictures from the L-System strings. Only after that he could pay attention to his actual research work i.e., analyzing the pictures to figure out the influence of music on growth of plants.

 

You are to write a program to convert L-System strings into pictures of trees, you need to be properly informed of the L-System. Aristid Lindenmayer (November 17, 1925 – October 30, 1989) was a Hungarian biologist who developed a formal language called L-systems or Lindenmeyer Systems to model plants. The L-System consists of the following components.

 

V : an alphabet of symbols.

S : a non-empty starting word (or seed)

P : a set of productions rules of the form a -> A , where a ε V and A is a string consisting of symbols from V only.

 

For the job at hand, Dablu has supported us with the following alphabet of the L-System he is using.

 

V = { U , L , l , R , r , f , P , p , [ , ]}

 

Since it is not our job to convert the plants into L-System strings, we are not really bothered about the seed or the production rules he uses to encode a plant into L-System string. We are concerned with interprating each of the symbols in his alphabet on the picture. According to Dablu, the procedure of drawing a plant from its L-System string should be considered similar to drawing a plant with a pencil on a paper. We start by putting the tip of the pencil on paper. Then draw line sements in various directions representing stems of the plant in various spatial orientations. Each of the symbols in V has a corresponding direction of line segment or any other artifact to be drawn on the paper, which is given in the following table. Note that the pencil keeps moving according to the drawing. Dablu has also told us that all the given strings will start with either ‘U’ or ‘[’.

 

 

Symbol

Drawn as

Interpretation

U

|

Upward stroke of pencil, drawing an upright stem/trank of the plant.

L

_

A horizontal leftward stroke, drawing a horizontal- stem.

l

\

Left inclined stroke, drawing a leftward inclined stem.

R

_

A horizontal rightward stroke, drawing a horizontal- stem.

r

/

Right inclined stroke, drawing a rightward inclined stem.

f

*

A flower.

p

o

A growing fruit.

P

O

A fully grown fruit.

[

 

Indicates the starting of a branch. Whatever is found after a ‘[’ symbol is on this branch of the plant. Note that there a branch itself can have one or more sub-branches as well.

]

 

Indicates the end of a branch. When this symbol is found, the pencil is brought back to the position from where this branch had started.

 

Input

 

There will be several lines of input. An L-System string on each line, terminating with a ‘\n’, containing up to 500 symbols from V and only from V. Input file terminates with EOF. You can assume that all given strings will be valid and will draw a plant if converted correctly.

 

Output

 

For each L-System string your output should be the picture of a correctly drawn plant enclosed in a rectangular frame similar to the ones shown in sample output. Note that the corners of the character at the corners of the rectangles are ‘.’(period). There should be no extra white space up/down/right/left of the plant inside the frame. If you need to overwrite any character while drawing, just go do it.

 

Sample Input                                                         Output for Sample Input

U[lf][rf]UU[lf][rf]UUP

U[L][R[Up]RR[Uf]RR]U

U[llf][rrf]UU[lf][rf]UUP

[U]l[UlU][LUrr[Uf]rr]

[U]l[LUrr[Uf]rr]UlU

U[rrRlUUU[r]l]ll[LpPf]U[UUUP][RUlLo]L

.-----.

|  O  |

|* | *|

| \|/ |

|* | *|

| \|/ |

|  |  |

.-----.

.-----------.

|   o   *   |

|_|_|_ _|_ _|

| |         |

.-----------.

.---------.

|    O    |

|  * | *  |

|*  \|/  *|

| \  |  / |

|   \|/   |

|    |    |

.---------.

.--------.

|    *  /|

|    |/  |

||  /    |

| /      |

||_|     |

|   \|   |

.--------.

.--------.

|    *  /|

|    |/  |

||  /    |

| \      |

||_|     |

|   \|   |

.--------.

.------------.

|  O      \ /|

| _|       | |

|  |\      | |

| _|_|     | |

|*_|        \|

|   \     /  |

|     \ /    |

|      |     |

.------------.


Problemsetter: K. Raiyan Kamal