Josip used to code in Logo. He loved to draw pictures, but those days are sadly over. Nostalgic, he decided to draw a line that represents the net worth of his company over a period of days.
For each of the days, he knows if the net worth of his company increased by one
unit (represented by +
), decreased by one unit (represented by -
), or remained
the same (represented by =
) during that day. Before the first day, the net worth
was equal to zero.
Josip will draw the line in a big infinite matrix of characters. Indices of matrix rows grow upwards, and indices of columns grow to the right. For the -th day he will draw some character in the -th column.
The character and the index of the row are decided by the following rules:
- If the net worth increased during the -th day, he will draw
/
in the row with index equal to the net worth at the beginning of the day. - If the net worth decreased during the -th day, he will draw
\
in the row with index equal to the net worth at the end of the day. - If the net worth didn't change during the -th day, he will draw
_
in the row with index equal to the net worth during the day.
All other cells are filled with .
.
Your task is to output the minimal matrix that contains the whole line, i.e. contains all characters /
,
\
and _
that Josip drew.
Input
The first line contains an integer , the number of days.
The second line contains a string of characters +
, -
and =
that represents how the company's net
worth changed over the given period.
Output
Output the described matrix.
Scoring
In test cases worth points the input won't contain the character -
.
Sample Input 1
7
++---==
Sample Output 1
./\....
/..\...
....\__
Sample Input 2
5
+=+=+
Sample Output 2
..._/
._/..
/....
Sample Input 3
4
--=+
Sample Output 3
\...
.\_/
Comments
Can somebody explain to me how to get the starting row?
Could someone explain the sample output 1 for me? I could not get that output following the rules outlined in the problem.
It might be easier to explain if you show the output that you get from your interpretation of the rules.
The best explanation I can currently give is just that it looks like the graph of a function going up twice, down three times, and staying flat twice.
Thank you for your response. From my interpretation: '/' at (0,1) position (net worth = 0 at the beginning of day 1). '/' at (1,2) (net worth = 1 at the beginning of day 2). '\' at (1,3) (net worth = 1 at the end of day 3). '\' at (0,4). '\' at (-1,5)=(3,5). '_' at (3,6). '_' at (3,7). Where did I go wrong? Thanks again.
It seems like you think that when the row-value goes negative the position of the drawing should loop around (like in python indexing). However, we instead want to continue going 'below the axis' (as we would when drawing a graph on the coordinate axes).
In particular, in Sample 1 the rows in the Sample Output are:
(The indices increase as we go upwards, as stated in the problem statement).
Make sure you come up with your own varied test cases. My lack of imagination in this regard hung me up for quite awhile. It should look like a proper dashed line on a dotted background.
A hard edge case is to guarantee the "minimal" matrix, which can be done either with complex logic or simply dropping lines that only consist of points...
Why is this worth as much as https://dmoj.ca/problem/dmopc20c2p1
it's the exact same problem lmao