Skip to content

平成21年度 秋期 ITパスポート試験 問54

This question's explanation and your answers so far.

問54
頻出度★☆☆

数字が書かれた箱を図のように積み上げてある。表に示す操作を,操作1,操作2,操作3,操作4の順に行った場合,操作4が終わったときの箱の状態はどれか。 図(下から上の順):1,2,2,3,4 表

操作名操作の内容
操作1箱を上から二つ取り出し,取り出した箱に書かれた値を加算した値を書いた箱を新たに一番上に積む。
操作2数字3を書いた箱を新たに一番上に積む。
操作3箱を上から三つ取り出し,取り出した箱に書かれた値の平均値を求める。その平均値を書いた箱を新たに一番上に積む。
操作4箱を上から二つ取り出し,取り出した箱に書かれた値の差の絶対値を求める。その絶対値を書いた箱を新たに一番上に積む。
出典 平成21年度 秋期 ITパスポート試験 問54
解説

問 54

  • Incorrectア

    This is a single level containing only 0. The final state has two levels, 1 and 2, so neither the number of levels nor the values match. Just before operation 4 the stack is 1, 2, 4 from the bottom, and the boxes taken are the top two, 4 and 2, whose absolute difference is |4-2|=2, not 0. Also, the box with 1 remaining at the bottom does not disappear.

  • イ

    正解 A stack of boxes behaves exactly like a last-in first-out structure (a stack): you always take from the top and place on the top. In the figure the initial state, from bottom to top, is 1, 2, 2, 3, 4 (five levels). Operation 1 takes the top two boxes, 4 and 3, and places a box with 4+3=7, so from the bottom it becomes 1, 2, 2, 7. Operation 2 takes nothing and only places a 3, so from the bottom it is 1, 2, 2, 7, 3 (five levels). Operation 3 takes the top three boxes, 3, 7, and 2, and places their average (3+7+2)/3=4, so from the bottom it becomes 1, 2, 4 (three levels). Operation 4 takes the top two boxes, 4 and 2, and places the absolute value of their difference, |4-2|=2, so the final state from the bottom is 1, 2 (two levels). Written from the top it is 2, 1, so choice イ is correct.

  • Incorrectウ

    This is three levels, 1, 2, 4 from the bottom, but that is the state before operation 4 is performed (right after operation 3 finishes). The question asks for the state when operation 4 has finished, so the step of taking the top two boxes, 4 and 2, and placing a 2 is still needed. This choice stops the operations one step too early.

  • Incorrectエ

    This is four levels, 1, 2, 2, 1 from the bottom, but the final state has two levels, so the number of levels does not match. In operations 1, 3, and 4 the number of boxes taken (2, 3, and 2) is larger than the single box placed each time, so the stack shrinks accordingly. Even counting the one level added by operation 2, the final number of levels is 5-1+1-2-1=2. The sequence of values does not match 1, 2 either.

ここがポイント
  • Stacking boxes is exactly a last-in first-out (LIFO) stack: both taking out and placing are always done at the very top.
  • For questions where several operations are applied in order, the reliable approach is to write down and track the state of the stack (levels and values) one operation at a time.
用語

Your answers