代码:
#!/usr/bin/env python
# encoding: utf-8
"""
@author: 侠之大者kamil
@file: 2.回形矩阵.py
@time: 2016/3/21 10:51
"""
def sankeMatric(n):
m = [[0] * n for x in range(n)]
p = 0
q = n-1
t = 1
while p < q:
for i in range(p,q):
m[p][i] = t
t +=1
for i in range(p,q):
m[i][q] = t
t +=1
for i in range(q,p,-1):
m[q][i] = t
t +=1
for i in range(q,p,-1):
m[i][p] = t
t +=1
p +=1
q -=1
if p ==q:
m[p][p] = t
return m
b = int(input("please input the number:"))
a = sankeMatric(b)
for l in a:
print(l) def func():
pass class Main():
def __init__(self):
pass if __name__ == '__main__':
pass