DRAWM - Draw Mountains

no tags 

You are a member of a team that is working in a new wonderful graphics program.
Your task is to write a module for drawing skylines of mountains. However, for now the
program is in beta version, so each skyline is discretized. This means that your module
receives as input a sequence of integers representing heights. Each pair of consecutive
heights in the sequence may differ by at most 1 and produces a column of output, each
column containing a single character. The particular character to write and its position
in the column depend on the pair of heights. When both heights are equal an underscore
(“ ”) must be printed. If the heigths within the pair increase or decrease, you must write
a slash (“/”) or a backslash (“\”), respectively. The position of the character in the
column is such that the skyline visually respect the given heights.
For instance, the sequence of heights (1, 2, 3, 2, 3, 3, 2, 1, 0) must produce the skyline shown
in the following figure.

    _
 /\/ \
/     \
       \

Notice that when the sequence of heights has C + 1 elements, the corresponding skyline
has only C columns. Given a sequence of heights, you must draw the skyline according
to the rules given above. See the examples for further clarification.

Input

The input contains several test cases, each one described in exactly two lines. The first
line contains an integer C indicating the number of columns of the skyline (1 ≤ C ≤ 70).
The second line contains C + 1 integers Hi separated by single spaces representing the
sequence of heights (0 ≤ Hi ≤ 30 for 1 ≤ i ≤ C + 1). You may assume that there exist
an height Hi = 0, and that the difference between succesive heights is at most 1 (i.e.
|Hi − Hi+1 | ≤ 1 for 1 ≤ i ≤ C). The last line of the input contains a single −1 and should
not be processed as a test case.

Output

For each test case output the correponding skyline, followed by a line with exactly three
asterisks (“***”). While writting the skyline, use only regular spaces, newlines, and the
three characters mentioned in the statement. Ths skyline must be left aligned and it
must contain exactly C columns. There must be no trailing spaces at the end of printed
lines, neither empty lines.

Example

Input:
8
1 2 3 2 3 3 2 1 0
3
1 0 0 1
-1

Output:
  _
 /\/ \
/     \
       \
***
\_/
***

hide comments
raschu: 2017-06-10 11:49:04

AC in one go!
Just another test case:
96
9 8 7 6 5 4 3 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 3 2 2 1 2 2 3 4 5 6 7 8 9 10 11 12 12 11 10 9 10 9 8 7 6 6 6 5 6 5 4 4 3 2 1 0 0 1 2 3 4 5 6 6 6 7 6 5 4 3 2 2 1 2 2 3 3 2 1 0 0 1 2 3 3 2 2 1 2 2 3 3 2 1 0


Last edit: 2017-06-10 11:53:08
Daniel: 2016-12-23 07:23:35

@Santiago Zubieta
Thanks Santiago.

:.Mohib.:: 2015-06-29 11:43:11

Nice One.... :)

Nebojsa: 2015-03-25 12:20:00

Great problem! My 100th on SPOJ :))

joud zouzou: 2013-05-18 12:22:29

I tried the test cases and even tried to print x instead of space like santiago zubieta said, eventhough i got WA, what would the problem be?

jaans: 2012-06-27 07:34:32

:D understud the ques completly wrng :P but when got the ques right :D guess what AC in first attempt :D and random_gal :* u r a genius

Loving Primes Yummy :D :): 2012-06-20 06:42:52

@Santiago Zubieta
Thanks for your explanation. Got AC in first attempt :)

Santiago Palacio: 2012-01-12 20:09:27

What i love the most of this problem, is that the result is fun.

Santiago Zubieta: 2011-06-13 08:51:40

I don't have any trailing spaces
I made it print 'x' instead of spaces to check if there were any trailing spaces and this comes out:

8
1 2 3 2 3 3 2 1 0
xxxx_
x/\/x\
/xxxxx\
xxxxxxx\
***
meaning after the last char, no more spaces are printed

and I've tried some weird cases such as:
***
14
0 1 2 3 3 2 2 1 2 2 3 3 2 1 0
xxx_xxxxxx_
xx/x\_xx_/x\
x/xxxx\/xxxx\
/xxxxxxxxxxxx\

hehehe =(
EDIT: Even thought all the cases I tried worked, there was something odd in the code which was fixed with a single value change!
Anyway, I hope that second case I wrote is useful for somebody to check their code (it was failing for me at first that second case)

Last edit: 2011-06-13 09:20:47
nagesh: 2011-06-12 06:43:19

Finally got AC...be aware of whitespaces..:D


Added by:Pablo Ariel Heiber
Date:2010-08-22
Time limit:1.919s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 VB.NET
Resource:FCEyN UBA ICPC Selection 2009