IOM 2021, Блиц — Задача 32

The Blitz-contest of IOM-2021

Условие

What is the output of the following code fragment?

Python code listing (printed as an image), 17 lines: n = 3; matrix = [[0 for i in range(n)] for j in range(n)]; cell, turn = 1, 0; while cell <= n * n: four for-loops over range(turn, n - turn), range(1 + turn, n - turn), range(n - 2 - turn, turn - 1, -1) and range(n - 2 - turn, turn, -1) assign cell to matrix[turn][i], matrix[i][n - 1 - turn], matrix[n - 1 - turn][i] and matrix[i][turn] respectively, each time with cell = cell + 1; then turn = turn + 1. Finally, for i in range(0, n) and for j in range(0, n), print(matrix[i][j], end = a space), with print() after each row.
A)B)C)D)E)
1 2 31 2 31 2 31 1 11 2 3
8 0 41 2 32 0 42 2 28 9 4
7 6 51 2 33 4 53 3 37 6 5
  • A
  • B
  • C
  • D
  • E

Отговори

Решение


Оригинал в Архива: iom-2021-blitz-tasks-eng.pdf · официални решения: iom-2021-blitz-answers-eng.pdf