![打印十字图思路](https://i-blog.csdnimg.cn/blog_migrate/09a92328c2b1dc5b25e2e133e5382056.png#pic_center)
个人觉得打印题主要是考查找规律的能力和细心,这里还有二维数组的运用吧。思路写在代码的注释中了,直接上码
n = int(input())
boundary = 5+(n-1)*2
data_left_up = [["."]*(boundary) for i in range(boundary)]
data_left_down = [["."]*(boundary) for i in range(boundary)]
data_right_up = [["."]*(boundary) for i in range(boundary)]
data_right_down = [["."]*(boundary) for i in range(boundary)]
def fillRow(a,b,rows,datas):
for i in range(a,rows):
datas[i][b] = '$'
def fillCol(a,b,cols,datas):
for j in range(b,cols):
datas[a][j] = '$'
"""①和②部分,注意奇偶的关系即可"""
for i in range(2,boundary,2):
fillRow(i,i-2,boundary,data_left_up)
for i in range(2,boundary,2):
fillCol(i-2,i,boundary,data_left_up)
for i in range(2,boundary,2):
data_left_up[i][i-1] = '$'
data_left_up[i][i] = '$'
data_left_up[i-1][i] = '$'
"""
③部分,即中间的部分从索引为[2,2]的部分开始,每次行数+2,
列数加1得到那三个位置的右下角那个,
根据这个位置可以容易得到另外两个[行不变,列-1][行-1,列不变]
"""
for i in range(boundary):
for j in range(boundary):
data_right_up[i][j] = data_left_up[i][boundary-1-j]
data_left_down[i][j] = data_left_up[boundary-1-i][j]
data_right_down[i][j] = data_left_up[boundary-1-i][boundary-1-j]
for i in range(boundary):
for j in range(boundary):
print(data_left_up[i][j],end="")
for j in range(1,boundary):
print(data_right_up[i][j],end="")
print("")
for i in range(1,boundary):
for j in range(boundary):
print(data_left_down[i][j],end="")
for j in range(1,boundary):
print(data_right_down[i][j],end="")
print("")