编程题

#include using namespace std;int main() {\tint n, i, j, x, y, nx, ny;\tint a[40][40];\tfor (i = 0; i < 40; i  )\t\tfor (j = 0; j < 40; j  )\t\t\ta[i][j] = 0;\tcin >> n;\ty = 0; x = n - 1;\tn = 2 * n - 1;\tfor (i = 1; i <= n * n; i  ) {\t\ta[y][x] = i;\t\tny = (y - 1   n) % n;\t\tnx = (x   1) % n;\t\tif ((y == 0 && x == n - 1) || a[ny][nx] != 0)\t\t\ty = y   1;\t\telse { y = ny; x = nx; }\t}\tfor (j = 0; j < n; j  )\t\tcout << a[0][j] << " ";\tcout << endl;\treturn 0;}

输入:3

输出:_________

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论