ArrayMatched
import os from jinja2 import Environment,FileSystemLoader def generateNewLackArray(ArrayList,count,TargetArray):
ArrayList=list(ArrayList)
newArrayList=[]
matchResult=[]
# i=0
for i in range(0,ArrayList.__len__()-count+1):
LackArray = ArrayList
if ArrayList[i]=="N":
continue CurrentValue=LackArray[i]
for tube in range(i+1,ArrayList.__len__()-count+2):
TotalValue=CurrentValue
Process=str(i+1)
newArray={}
for c in range(0,count-1): index=tube+c
if LackArray[index]=="N":
continue TotalValue=TotalValue+LackArray[index]
Process=Process+"+"+str(index+1) newArray[str(TotalValue)]=Process
if TotalValue in TargetArray: result={}
result[Process]=list(TargetArray).index(TotalValue)+1
matchResult.append(result)
TargetArray[(list(TargetArray).index(TotalValue))]="N" popArray=Process.split("+")
popArray.reverse()
for p in popArray:
ArrayList[(int(p)-1)]="N"
break # i+=1 # print(ArrayList)
# print(TargetArray)
return matchResult,ArrayList,TargetArray def getArrayList(path):
if not os.path.exists(path):
return []
with open(path,"r") as reader:
ArrayList=reader.read().split("\n")
for i in range(0,ArrayList.__len__()):
if ArrayList[i]=="":
ArrayList.pop(i)
return ArrayList def moretimes(ArrayList,TargetList):
ArrayList=list(ArrayList)
TargetList=list(TargetList)
Result=[]
for count in range(2,ArrayList.__len__()-1):
matchResult,ArrayList,TargetList= generateNewLackArray(ArrayList,count,TargetList)
Result=Result+matchResult
return Result def generateHTML(InputArray,Target,Result):
env=Environment(loader=FileSystemLoader("./"))
template=env.get_template("template.html")
with open("result.html","w+") as f:
html_content=template.render(InputArray=InputArray,Target=Target,Result=Result)
f.write(html_content) if __name__=="__main__":
a=[8,1,2,3,4,1,2,3,4,1,2,1,1,1,1,1,1,1]
b=[1,3,7,6,7]
a=getArrayList("1.txt")
a=getArrayList("2.txt")
generateHTML(a,b,moretimes(a,b))
<html>
<body> <table border="1" width = "10%" cellspacing='0' cellpadding='0' align='left'>
<tr>
<th>序号</th>
</tr>
{% for id in range(1,InputArray.__len__()+1) %}
<tr align='center'>
<td>{{ id }}</td>
</tr>
{% endfor%}
</table> <table border="1" width = "20%" cellspacing='0' cellpadding='0' align='left'>
<tr>
<th>值</th>
</tr>
{% for item in InputArray %}
<tr align='center'>
<td>{{ item }}</td>
</tr>
{% endfor%}
</table> <table border="1" width = "30%" cellspacing='0' cellpadding='0' align='left'>
<tr>
<th>公式</th>
<th>结果</th> </tr> {% for item in Result %}
<tr align='center'>
{% for k,v in item.items()%}
<td>{{ k }}</td>
<td>{{ v }}</td>
{% endfor%}
</tr>
{% endfor%}
</table> <table border="1" width = "10%" cellspacing='0' cellpadding='0' align='left'>
<tr>
<th>序号</th>
</tr>
{% for id in range(1,Target.__len__()+1) %}
<tr align='center'>
<td>{{ id }}</td>
</tr>
{% endfor%}
</table> <table border="1" width = "20%" cellspacing='0' cellpadding='0' align='left'>
<tr>
<th>值</th>
</tr>
{% for item in Target %}
<tr align='center'>
<td>{{ item }}</td>
</tr>
{% endfor%}
</table>
</body>
</html>
ArrayMatched的更多相关文章
随机推荐
- 非线性函数图像表示(GLSL)
说明:绘图区域x轴(0->1),y轴(0->1); 1.y = 0.5 + sqrt(x * (1 - x)) 2.y = smoothstep(a , b , x) y = smooth ...
- 如何在WIN7下安装虚拟机linux系统
需要支持多个平台的IT管理员经常会遇到如何在Windows 7计算机上安装Linux的问题.幸运的是有多种方法可供选择:双系统.Linux虚拟机和U盘引导. 当需要用到Windows 7和Linux时 ...
- ServletContainerInitializer
在web容器启动时为提供给第三方组件机会做一些初始化的工作,例如注册servlet或者filtes等,servlet规范中通过ServletContainerInitializer实现此功能. 每个框 ...
- eve-ng
eve-ng eve-ng采用的是和web-iou一样的B/S模式,进步的地方是它只需拖动鼠标就可以搭建拓朴,比web-iou要直观. 此虚拟机已经集成了IOL的L2.L3以及vIOS的L ...
- web题
@php绕过https://www.cnblogs.com/leixiao-/p/9786496.html @step1:F12 step2:抓包 @任何url http://118.25.14.4 ...
- 【Python开发】增强的格式化字符串format函数
自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足.那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱. 语法 它通过{}和 ...
- mysql常用排查命令
1.查看服务器使用状态 mysqladmin -uroot -p -S /tmp/mysql.sock -r -i 1 ext |\ awk -F"|" \ "BEGIN ...
- 2. zookeeper介绍及集群搭建
ZooKeeper 概述 Zookeeper 是一个分布式协调服务的开源框架. 主要用来解决分布式集群中 应用系统的一致性问题,例如怎样避免同时操作同一数据造成脏读的问题. ZooKeeper 本质上 ...
- plpython 中文分词Windows 版
windows 下安装版本匹配python-3.4.3.amd64.msipostgresql-10.1-2-windows-x64.exe create language plpython3u;se ...
- Python中的xrld模块
一. 什么是xrld模块 python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库. 二. 使用介绍 . empty(空的), number, ...