MWC '15 #8 P2: ASCII Art

View as PDF

Submit solution

Points: 7
Time limit: 0.6s
Memory limit: 256M

Author:
Problem type

aurpine used to be a pixel painter. However, times have changed. Technology has advanced. These days, it's all about ASCII. Foreign to the new style, he has become depressed. Cheer him up by writing a program featuring the primitive tools he knows from pixel painting. Each operation will be given to you on a single line.

The features and operations are:

  • c n change the colour used to the given ASCII character n. The letter c will strictly be followed by a single space, followed by the character. The colour could be a space.
  • r x y w h draw a rectangle starting at (x, y) (0 \le x, y) with a width (columns) and height (rows) of w and h respectively (1 \le w, h).
  • f x y w h draw a filled rectangle starting at (x, y) (0 \le x, y) with a width (columns) and height (rows) of w and h respectively (1 \le w, h).
  • h y a b draw a horizontal line on row y (0 \le y) from column a to b (inclusive) (0 \le a \le b).
  • v x a b draw a vertical line on column x (0 \le x) from row a to b (inclusive) (0 \le a \le b).
  • d x y draw a dot (pixel) at (x, y) (0 \le x, y).
  • s save the picture (print the art and close your program).

The default (starting) colour is a period .. The grid initiates with a width and height of 0. It expands so that any edited character/pixel is included in the rectangular area. Note that the point (0,0) is not necessarily always drawn. The background (where nothing has been drawn) defaults to a space character  . When printing, pad and trail spaces so that the output consists of R rows with C characters on each line where R and C are respectively the rows and columns expanded to. Characters get overwritten when drawn.

Input Specification

1 \le C, R \le 100

The farthest pixel ever drawn is at (99, 99).

There will be at most 100 commands. Input will always end with s on a single line. The finished artwork will never be empty.

Output Specification

A grid of C by R characters – the resulting artwork created by aurpine.

Note: Output must match exactly.

Sample Input 1

r 1 1 5 3
c -
h 3 2 4
c |
v 2 1 3
c +
d 2 3
s

Sample Output 1

.|...
.|  .
.+--.

Explanation for Sample Output 1

First, the 5 by 3 rectangle is drawn with the default colour.

.....
.   .
.....

Then the colour is changed to -. And a horizontal line is drawn.

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

The colour is changed once again and a vertical line is drawn.

.|...
.|  .
.|--.

The colour is changed to + and a dot is drawn to yield the final drawing.

.|...
.|  .
.+--.

Sample Input 2

c X
f 2 5 8 2
c x
r 1 2 10 3
d 6 5
d 10 5
d 9 3
c >
f 4 3 5 2
c -
d 6 3
d 8 3
d 11 3
d 5 4
d 7 4
d 9 4
c O
d 3 3
c /
d 3 1
d 5 1
d 7 1
c ,
d 9 1
c `
d 11 5
c  
d 1 2
d 10 2
d 4 3
d 2 4
d 3 4
d 4 5
d 8 5
d 2 6
d 6 6
s

Sample Output 2

  / / / ,  
 xxxxxxxx  
x O >->-xx-
x  >->->-x 
 XX XxX Xx`
  XXX XXX  

Comments


  • 1
    Jeffmagma  commented on May 23, 2016, 10:48 p.m.

    If a line has trailing spaces at the end, should we output it or go directly to the next line?


    • -3
      aurpine  commented on May 24, 2016, 12:22 a.m.

      Output.

      When printing, pad spaces so that output consists of R rows with C characters on each line


  • 0
    richardyi25  commented on May 22, 2016, 12:54 p.m.

    Is length horizontal and width vertical?


    • -1
      aurpine  commented on May 22, 2016, 1:25 p.m.

      Yes. Changed to w (width) and h (height) for easier comprehension. Shouldn't affect the input.