#C14104. Multiplayer Canvas Drawing Simulator
Multiplayer Canvas Drawing Simulator
Multiplayer Canvas Drawing Simulator
This problem requires you to simulate a simple canvas drawing application that supports basic operations over a virtual 20×20 canvas. The canvas is initially blank (filled with '.') and supports the following commands:
DRAW x y c
: Draws the characterc
at columnx
and rowy
(0-indexed). If the coordinates are out-of-bounds, ignore the command. When drawing, the drawn color overwrites any previous content.UNDO
: Undoes the lastDRAW
command. This reverts the cell affected by that command to blank (i.e. '.').REDO
: Redoes the last undoneDRAW
command, applying it again.PRINT
: Prints the entire canvas to standard output, each row on a separate line.
You should implement the canvas with an undo/redo functionality that only keeps track of draw operations. Note that if a cell is drawn twice, an UNDO
only removes the most recent operation and does not restore the previous content. All commands are provided via standard input (stdin) and outputs must be sent to standard output (stdout).
For example, executing the commands:
DRAW 10 10 X UNDO REDO PRINT
should result in the character X
appearing at position \( (10,10) \) in the printed canvas.
inputFormat
The input consists of several commands, one per line, read from standard input. The commands are:
DRAW x y c
— Draw characterc
at coordinates \(x\) and \(y\).UNDO
— Undo the most recent draw operation.REDO
— Redo the most recently undone operation.PRINT
— Print the canvas and terminate the program.
The canvas size is fixed at 20 × 20 and indices are 0-indexed. You can assume that there will be at least one PRINT
command, which will always be the last command.
outputFormat
When the PRINT
command is encountered, output the state of the 20 × 20 canvas. Each line represents a row of the canvas and contains exactly 20 characters. Blank cells are represented by a dot ('.').
DRAW 10 10 X
PRINT
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
..........X.........
....................
....................
....................
....................
....................
....................
....................
....................
....................
</p>