Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
91943 sh25_shenpy 方阵填数 C++ 解答错误 1 MS 268 KB 829 2026-06-19 16:41:35

Tests(0/3):


#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 << setw(2) << a[i][j] ; } cout << endl; } return 0; }


测评信息: