参考代码:
# 重点就是判断条件的顺序 n = int(input()) square = [[0] * (2 * n - 1) for _ in range(2 * n - 1)] x, y = 0, n - 1 value = 1 while value <= (2 * n - 1) ** 2: square[x][y] = value value += 1 if x == 0 and y == 2 * n - 2 or x - 1 >= 0 and y + 1 < 2 * n - 1 and square[x - 1][y + 1] > 0: x = x + 1 elif x == 0: x, y = 2 * n - 2, y + 1 elif y == 2 * n - 2: x, y = x - 1, 0 else: x, y = x - 1, y + 1 for row in square: for num in row: print(num, end=" ") print()
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:818 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:268 |
1012题解浏览:938 |
Tom数 (C语言代码)浏览:517 |
简单的a+b (C语言代码)浏览:1024 |
1162答案错误,为什么浏览:700 |
10月月赛题解浏览:554 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:827 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:1260 |
众数问题 (C语言代码)浏览:660 |