Programming contests

Informatikai versenyfeladatok, gyakorló feladatsor, 2012. február 20.

March 1, 2012, 12:00 AM – April 1, 2012, 12:00 AM

Graphical Editor

The simple graphical editor deals with a rectangular table M × N (1 ≤ MN ≤ 250). Each pixel of the table has its colour. The picture is formed from this square pixels.

The problem is to write a program, which simulates an interactive work of the graphical editor.

Input Specification

Input consists of the editor commands, one per line. Each command is represented by one Latin capital placed in the very beginning of the line. If the command supposes parameters, all the parameters will be given in the same line separated by space. As the parameters there may be:

  • the coordinates of the pixel – two integers, the first one is the column number and belongs to 1..M, the second one is the row number and belongs to 1..N, the origin is in the upper left corner of the table;
  • the colour – the Latin capital;
  • file name – in MSDOS 8.3 format.

The editor deals with the following commands:

Command Action
I M N Creates a new table M × N. All the pixels are colored in white (O).
C Clears the table. The size remains the same. All the pixels became white (O).
L X Y C Colors the pixel with coordinates (XY) in colour C.
V X Y1 Y2 C Draws the vertical segment in the column X between the rows Y1 and Y2 inclusive in colour C.
H X1 X2 Y C Draws the horizontal segment in the row Y between the columns X1 and X2 inclusive in colour C.
K X1 Y1 X2 Y2 C Draws the filled rectangle in colour C. (X1Y1) is the upper left corner, (X2Y2) is the lower right corner of the rectangle.
F X Y C Fills the region with the colour C. The region R to be filled is defined as follows. The pixel (XY) belongs to this region. The other pixel belongs to the region R if and only if it has the same colour as pixel (XY) and a common side with any pixel which belongs to this region.
S name Writes the picture in the file name.
X Terminates the session.

Output Specification

Every time the command S name meets, you should output the file name name and the current table, row by row. Each row is represented by a pixels' colours series, see the output sample.

Errors

If as a command there will be a character different from I, C, L, V, H, K, F, S, X, the editor should ignore the whole line and pass to the next command.

In case of other errors the program behaviour is unpredictable.

Sample Input

  1. I 5 6
  2. L 2 3 A
  3. S one.bmp
  4. G 2 3 J
  5. F 3 3 J
  6. V 2 3 4 W
  7. H 3 4 2 Z
  8. S two.bmp
  9. X
download as text file

Output for Sample Input

  1. one.bmp
  2. OOOOO
  3. OOOOO
  4. OAOOO
  5. OOOOO
  6. OOOOO
  7. OOOOO
  8. two.bmp
  9. JJJJJ
  10. JJZZJ
  11. JWJJJ
  12. JWJJJ
  13. JJJJJ
  14. JJJJJ
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024