Capital OneOA #18
Rotate Matrix Over Diagonals
估计中等可在线判题
考点(AI 标注)模拟/实现原地数组
You are given a non-empty n×n square matrix and a non-negative count turns. In each turn, the elements on both main diagonals stay in place, and the remaining four triangular regions rotate 90 degrees clockwise: a non-diagonal element at original coordinate (r,c) moves to (c,n−1−r), with coordinates counted from 0. Output the matrix after repeating this turns times. This mapping matches the fixed original 5×5 example entry by entry; the public source image on the original page explicitly shows a clockwise rotation with both diagonals fixed.
输入格式
The first line contains n turns, followed by n lines of n integers each, separated by whitespace; LF/CRLF line endings and a trailing EOF are accepted. The original gave no numeric upper bounds; this site publicly adapts them to Java types: n≥1 (a non-empty square matrix), elements in −2147483648..2147483647, and turns 0..2147483647. n is limited only by the existing 32MiB input budget, with no separate smaller cap; 4095 is derived from the shortest-encoding budget and is not a source constraint. Empty matrices and negative turn counts are not supported as extensions.
输出格式
Output the rotated matrix as n lines of n integers each; do not output n.
样例 1
输入:
5 1
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
输出:
1 16 11 6 5
22 7 12 9 2
23 18 13 8 3
24 17 14 19 4
21 20 15 10 25
样例 2
输入:
2 2147483647
1 2
3 4
输出:
1 2
3 4
样例 3
输入:
1 0
-2147483648
输出:
-2147483648
样例说明
The first public example keeps the original complete 5×5 input and output; both diagonals, 1/7/13/19/25 and 5/9/13/17/21, stay fixed. a 2×2 matrix is entirely diagonal and stays unchanged after any number of turns; a 1×1 matrix and zero turns likewise leave the matrix unchanged. The source image was downloaded separately and bound to its own hash.