Skip to content

平成23年度 秋期 ITパスポート試験 問89

This question's explanation and your answers so far.

問89
頻出度★☆☆

文字や図形を白黒で縦 7 画素,横 7 画素のディジタル画像で表すとき,数字の“0”を図 1 のように表現する。このディジタル画像を画素データとして出力する処理,画素データを圧縮する処理及びディジタル画像を回転させる処理について考える。 図 1 数字の“0”のディジタル画像

1列2列3列4列5列6列7列
1行□□■■■□□
2行□■□□□■□
3行□■□□□■□
4行□■□□□■□
5行□■□□□■□
6行□■□□□■□
7行□□■■■□□

画素データを出力する処理の概要と圧縮する処理の概要は,次のとおりである。 〔画素データを出力する処理の概要〕 (1) 画素の色が白のときは“w”,黒のときは“b”を画素データとして出力する。 (2) 1 行 1 列,1 行 2 列,…,1 行 7 列,2 行 1 列,2 行 2 列,…,7 行 7 列の順番に各位置の画素データを出力する。 (3) 画素データを出力する際は,各画素データの間をコンマ“,”で区切る。 (4) 図 1 の画素データを出力した結果は次のとおりになり,文字数はコンマを含めて 97 文字になる。 w,w,b,b,b,w,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,b,w,w,w,b,w,w,w,b,b,b,w,w 〔画素データを圧縮する処理の概要〕 (1) 同じ色の画素データが連続する場合,“w”又は“b”の後に連続する画素の数をつなげて出力する。例えば,“b,b,b”は“b3”になる。 (2) 図 1 の画素データを圧縮した結果の出力は次のとおりになり,文字数はコンマを含めて 64 文字になる。 w2,b3,w3,b,w3,b,w2,b,w3,b,w2,b,w3,b,w2,b,w3,b,w2,b,w3,b,w3,b3,w2 画素データを圧縮せずに出力した場合,29 文字目から 41 文字目が,“w,b,w,w,w,b,w”になるディジタル画像はどれか。

出典 平成23年度 秋期 ITパスポート試験 問89
解説

問 89

  • Incorrectア

    For the digit “2”, row 3 is □□□□■□□ (only column 5 is black, partway along the stroke that slants down to the left), so the output is “w,w,w,w,b,w,w”, which does not match. Note that row 2 of “2” is □■□□□■□, the same arrangement as the one given in the question, but row 2 is pixels 8 to 14, that is characters 15 through 27, not the range starting at character 29. This is a trap meant to make you mistake which row it is.

  • Incorrectイ

    For the digit “5”, row 3 is □■■■■□□ (columns 2 to 5 are black, because the middle horizontal bar falls on row 3), so the output is “w,b,b,b,b,w,w”, which does not match.

  • Incorrectウ

    In the digit “6”, the loop lies in the lower half, so row 3 contains only the single pixel of the stroke coming down on the left: □■□□□□□. The output is “w,b,w,w,w,w,w”, and because column 6 is white it does not match.

  • エ

    正解 Under the output rule, one pixel becomes one character (w or b), and one comma is inserted between adjacent pixels. In other words, the string is laid out as “character, character, character, …” with a period of two characters, so the n-th pixel appears at character position 2n-1. Therefore the 29th character corresponds to pixel (29+1)÷2 = 15, and the 41st character corresponds to pixel (41+1)÷2 = 21. Since one row holds 7 pixels, pixels 1 to 7 are row 1, pixels 8 to 14 are row 2, and pixels 15 to 21 are exactly row 3. The image we are looking for must therefore satisfy “row 3 = w,b,w,w,w,b,w”, that is □■□□□■□, with only column 2 and column 6 black. In choice エ, the digit “9” has a closed loop in its upper part, and the left and right vertical strokes of that loop fall exactly on columns 2 and 6 in row 3, so row 3 becomes □■□□□■□. Hence the correct answer is エ.

ここがポイント
  • Mapping between character position and data index when a separator is included: if the separator is one character long, the n-th datum sits at character 2n-1; conversely, character k corresponds to datum number (k+1)÷2. Dividing further by the 7 pixels per row then identifies the row and column (pixels 15 to 21 → row 3, columns 1 to 7).
  • The theme of this group question is run-length encoding, which replaces a run of identical values with “value + run length” and is a representative example of lossless compression. As a preliminary step to that, this question tests whether you can correctly read that uncompressed pixel data is arranged in scan order (from the top left toward the right, row by row from top to bottom).
用語

Your answers