← 返回 stripe 的题目列表Bitmap Character Lookup: Print, Compress/Decompress, and Manipulate
类型:online_judge
Bitmap Character Lookup Table: Print, Compress/Decompress, and Manipulate (3 phases)
Implement a small “bitmap font” system. The system maintains a lookup table mapping a character to an H×W 2D matrix of 0/1 pixels:
0 = background pixel
1 = foreground pixel
Input
Read from stdin:
Two integers H W (bitmap height and width)
An integer N (number of characters in the lookup table)
Then N blocks, each containing:
One line: a single character c
Next H lines: each a length-W string of only 0 and 1 describing the bitmap for c
An integer Q (number of queries)
Next Q lines, each query is one of:
PRINT c: print bitmap for c
COMPRESS c: output compressed form (Phase 2)
DECOMPRESS c: decompress the stored compressed data for c and print
INVERT c: invert pixels (0↔1) and print (must reuse Phase 2 logic)
Phase 1: Basic Printing (PRINT)
For PRINT c:
Output H lines, each containing W digits separated by spaces.
Phase 2: Compression & Decompression (COMPRESS / DECOMPRESS)
Use row-wise Run-Length Encoding (RLE):
For each row, scan left to right and group consecutive equal bits into (bit, count) segments.
Output the compressed result as:
H lines
Each line prints segments as bit:count separated by single spaces.
Example: raw row 000010 becomes 0:4 1:1 0:1.
For DECOMPRESS c:
Decompress the stored RLE back to an H×W bitmap
Print it using the Phase 1 format.
Phase 3: Manipulation & Reuse (INVERT)
For INVERT c:
Invert all pixels (0→1, 1→0)
Print the inverted bitmap in Phase 1 format
The implementation must reuse Phase 2 logic (e.g., decompress then invert then print; or reuse common printing/decompression helpers).
Constraints
1 ≤ H, W ≤ 50
1 ≤ N ≤ 100
1 ≤ Q ≤ 200
Example
Input:
10 6
1
J
000010
000010
000010
000010
000010
000010
100010
011100
000000
000000
4
PRINT J
COMPRESS J
DECOMPRESS J
INVERT J
Output (the PRINT J part):
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
1 0 0 0 1 0
0 1 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
(Other commands should output according to the specification.)
Example
Input
10 6
1
J
000010
000010
000010
000010
000010
000010
100010
011100
000000
000000
1
PRINT J
Output
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
1 0 0 0 1 0
0 1 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0