| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 91941 | sh25_shenpy | 方阵填数 | C++ | 输出格式错误 | 1 MS | 260 KB | 824 | 2026-06-19 16:40:56 |
#include <iostream> #include <iomanip> using namespace std; const int MAX = 105; int a[MAX][MAX]; int main() { int n; cin >> n; int x = 0, y = n - 1; int num = 1; a[x][y] = num++; while (num <= n * n) { // 向下 while (x + 1 < n && !a[x + 1][y]) a[++x][y] = num++; // 向左 while (y - 1 >= 0 && !a[x][y - 1]) a[x][--y] = num++; // 向上 while (x - 1 >= 0 && !a[x - 1][y]) a[--x][y] = num++; // 向右 while (y + 1 < n && !a[x][y + 1]) a[x][++y] = num++; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cout << a[i][j] << " "; } cout << endl; } return 0; }