IPA FE Subject A sample Question 6
A question IPA Japan published in 基本情報技術者試験 科目A サンプル問題 問6, translated into English. ITPEC is based on the same exams.
When the flowchart in Figure 1 was executed with array A in the state shown in Figure 2, array B came to be in the state shown in Figure 3. Which of the following is the operation to be inserted into blank a in Figure 1? Here, the elements of arrays A and B are A(i, j) and B(i, j), respectively.
Figure 1 Flowchart
(Note) The repetition specification of a loop limit shows variable name: initial value, increment, final value.
Figure 2 State of array A
Figure 3 State of array B after execution
Explanation
B(j, 7 − i) ← A(i, j) — Figure 3 is Figure 2 turned 90° clockwise, so each row of A becomes a column of B, read from the top down.
The double loop visits every element A(i, j) once, so blank a only has to say where each element lands. Follow two strokes of the F:
- •Row 0 of A, columns 1 to 6, appears in B as column 7, rows 1 to 6: A(0, j) goes to B(j, 7)
- •Column 1 of A, rows 0 to 7, appears in B as row 1, columns 7 down to 0: A(i, 1) goes to B(1, 7 − i)
Both fit B(j, 7 − i): the new row is the old column, and the new column is 7 − i. Row 3 of A, columns 1 to 4, then lands in column 4, rows 1 to 4, as Figure 3 shows.
Answer (d)
Why not others:
- •(a) — turns the array 180°: row 0's asterisks would land in row 7, columns 1 to 6
- •(b) — turns it 90° anticlockwise: row 0 would become column 0, rows 1 to 6
- •(c) — mirrors it left to right: row 0 would still hold columns 1 to 6, with the stem moved to column 6
Key rule: Turning an n × n array 90° clockwise moves element (i, j) to (j, n − 1 − i); test a candidate formula on one row of the picture before trusting it.
Algorithm and Programming · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.