编程题
#includeusing 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
输出:_________
发表评论 取消回复