| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91748 | sh25_shenpy | 数字正方形 | C++ | 解答错误 | 2 MS | 252 KB | 733 | 2026-06-15 19:35:09 |
#include <bits/stdc++.h> using namespace std; int dx[] = {0 , -1 , 0 , 1} ; int dy[] = {1 , 0 , -1 , 0} ; int main() { int n; while(cin >> n) { int a[11][11] , pos = 1 ; memset(a , 0 , sizeof a) ; int x = 1 , y = 1 ; for(int i = 1 ; i <= n * n ; i++ ) { a[x][y] = i ; if(x + dx[pos] > n || x + dx[pos] < 1 || y + dy[pos] > n || y + dy[pos] < 1) pos = (pos + 1) % 4 ; x += dx[pos] , y += dy[pos] ; } for(int i = 1 ; i <= n ; i++) { for(int j = 1 ; j <= n ; j++) cout << a[i][j] << ' ' ; cout << endl ; } } return 0; }