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的更多相关文章

随机推荐

  1. k8s报错日志查看

    看系统日志 cat /var/log/messages 用kubectl 查看日志 # 注意:使用Kubelet describe 查看日志,一定要带上 命名空间,否则会报如下错误[root@node ...

  2. Cocos2d-x入门之旅

    Cocos通过动作(Action)让精灵动起来,把数个动作组成序列(Sequence)就能让精灵做出连续的动作,在动作中我们可以改变精灵的位置,旋转角度,缩放比例,等等 动作(Action)# 首先我 ...

  3. 备份和恢复IMail数据/IMail的服务端口

    1.备份和恢复IMail数据 首先你需要备份它的系统文件.方法是将“\imail”整个目录树复制下来. 其次还需要备份它的注册表.可选“localhost→General→Backup”来复制:或打开 ...

  4. react和vue配置本地代理

    React 在react中配置开发环境下的本地代理相对比较简单,直接在package.json文件中修改即可. 但是这样做有其局限性,如果开发中代理多个接口的时候将无法满足需求,我们需要的是下面这种的 ...

  5. A = min(1, max(0, A))

    Crop A into [0, 1]:

  6. lambda常用方法

    一:forEach()  循环遍历 List<Integer> costBeforeTax = Arrays.asList(100, 200, 300, 400, 500); costBe ...

  7. java中利用hanlp比较两个文本相似度的步骤

    使用 HanLP - 汉语言处理包 来处理,他能处理很多事情,如分词.调用分词器.命名实体识别.人名识别.地名识别.词性识别.篇章理解.关键词提取.简繁拼音转换.拼音转换.根据输入智能推荐.自定义分词 ...

  8. delphi 连接各中数据库方法

    ---恢复内容开始--- 数据库连接字符串的拼写规则的决定条件: • 连接的数据库的类型:SQL Server,Oracle,MySQL,Acess,MogoDB,Visual FoxPro(dBAS ...

  9. hdfs基本文件操作

    编程实现下列要求: 1.创建一个自己姓名首字母的文件夹 2.在文件夹下创建一个hdfstext1.txt文件,项文件内输入“班级学号姓名HDFS课堂测试”的文字内容: 3.在文件夹下在创建一个好的fs ...

  10. MySQL的事务和锁

    MySQL的事务和锁   阅读目录 什么是事务 事务:是数据库操作的最小工作单元,是作为单个逻辑工作单元执行的一系列操作:这些操作作为一个整体一起向系统提交,要么都执行.要么都不执行:事务是一组不可再 ...