2.python算法之回形矩阵
Posted 侠之大者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.python算法之回形矩阵相关的知识,希望对你有一定的参考价值。
代码:
#!/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
以上是关于2.python算法之回形矩阵的主要内容,如果未能解决你的问题,请参考以下文章