2.python算法之回形矩阵
2016-03-21 18:00
423 查看
代码:
#!/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
相关文章推荐
- python系列之 RabbitMQ -- Publish/Subscribe
- Ubuntu15.10下如何使用EasyGui模块开发Python GUI
- Ubuntu15.10下如何使用EasyGui模块开发Python GUI
- [LeetCode]题解(python):123-Best Time to Buy and Sell Stock III
- numpy使用指南
- win7 python3.5用pip
- python web开发
- python中给程序加锁之fcntl模块的使用
- PAT 乙级 1017. A除以B
- Learning Python(17)--多线程编程之线程的局部变量
- [LeetCode]题解(python):122-Best Time to Buy and Sell Stock II
- [LeetCode]题解(python):121-Best Time to Buy and Sell Stock
- Python 入门
- zabbix调用sendsms.py脚本,发送短信
- [置顶] 【Python】python使用中踩过的坑
- [LeetCode]题解(python):120-Triangle
- python系列之 RabbitMQ - work queues
- [LeetCode]题解(python):119-Pascal's Triangle II
- python使用数据库
- windows环境下安装python模块大招