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的更多相关文章
随机推荐
- Hibernate5+Spring4整合
(1) pom.xml <!--Spring Object/Relational Mapping --> <dependency> <groupId>org.spr ...
- python中的set集合
当使用爬虫URL保存时,一般会选择set来保存urls,set是集合,集合中的元素不能重复,其次还有交集,并集等集合的功能, 爬虫每次获取的网页中提取网页中的urls,并保存,这就需要利用urls = ...
- 组件推荐Forloop.HtmlHelpers 用来实现MVC的js加载顺序
最近在开发的时候遇到js加载顺序的问题,layui在底部声明了js,但是我想在页面其他地方使用分布视图,分布视图内有自己的js逻辑,发现不能执行,一看就发现,这里的js应该加在layui后面执行才能有 ...
- 描述下fastJSON,jackson等等的技术
①Jackson:依赖的jar包较少,简单易用性能高,更新速度也比较快,但是对于复杂类型的json转换bean会出 现问题,一些集合Map,List的转换出现问题,对于复杂类型的bean转换Json, ...
- OpenStack组件——Glance镜像服务
1.glance介绍 Glance是Openstack项目中负责镜像管理的模块,其功能包括虚拟机镜像的查找.注册和检索等. Glance提供Restful API可以查询虚拟机镜像的metadata及 ...
- IP划分
30.112.0.0 255.255.224.0/ 30.112.32.0 255.255.248.0 30.112.36.0 255.255.252.0 30.112.38.0 255.255. ...
- __str__,__repr__,__add__
class School: def __init__(self,name,addr,type): self.name=name self.addr=addr self.type=type def __ ...
- Emgu 学习(7)threshold ,图像过滤
Threshold 代码如下 static void Main(String[] args) { Mat img = CvInvoke.Imread(@"C:\Users\dell\Pict ...
- json字段为null时输出空字符串
Map < String , Object > jsonMap = new HashMap< String , Object>(); jsonMap.put(); jsonMa ...
- C# 面向对象5 this关键字和析构函数
this关键字 1.代表当前类的对象 2.在类当中显示的调用本类的构造函数(避免代码的冗余) 语法: ":this" 以下一个参数的构造函数调用了参数最全的构造函数!并赋值了那些不 ...