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. python-爬虫-史书典籍

    import requests import os from lxml import html import time def get_title_url(tree): '''一级 获取标题''' # ...

  2. 【HANA系列】SAP HANA SQL截取字符串

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL截取字符 ...

  3. idea退出提醒 打开

    有时候会误点下面的勾选框,导致以后直接退出,没有提示,很不方便,经常误点关闭,再次打开又要等很久 如何设置回来? File-Setting-Appearance&Beha-System Set ...

  4. Spring是什么? 什么是IOC(Inversin of control)? 什么是AOP (Aspect-Oriented Programming)?

    spring是一个开源容器框架,可以接管web层.service层.dao层.持久层的组件,spring底下是一个bean工厂,用户产生各种bean,spring可以配置各种bean,和维护bean与 ...

  5. Bootstrap+JSP实例学习笔记一.简单的带登录功能的首页

    前言 Bootstrap 是流行的 HTML.CSS 和 JS 框架,用于开发响应式布局.移动设备优先的 WEB 项目.源自于twiteer内部的开发框架. 当前(2019-05)最新版本是v3.3. ...

  6. NoSQL--leveldb

    什么是leveldb: leveldb它是一个 NOSQL 存储引擎,它和 Redis 不是一个概念.Redis 是一个完备的数据库,而 LevelDB 它只是一个引擎. LevelDB 还可以将它看 ...

  7. 树莓派4B 串口通信

    提前下载安装Glade图形编辑器 参考 树莓派4B安装netcore 环境部署.发布.执行操作 准备串口设备本文使用串口控制继电器设备 如图 1.发现串口 void GetSerialPort() { ...

  8. 继续做一道linux的企业 面试题

    把/dongdaxia目录及其子目录小所有以拓展名.sh结尾的文件中包含dongdaxia的字符串全部替换为dj. 解答:这道题还是用到了三剑客里的sed: 第一步:先在/dongdaxia目录及其子 ...

  9. 5.写一个sh脚本,可以通过一台机器控制多台机器

    先创建一个脚步文件 对这个脚本进行编辑 [hadoop@node1 ~]$ vim xcall.sh 给脚本赋予权限 执行脚本 把脚本移动到 /usr/local/bin/目录下 [hadoop@no ...

  10. 查找担保圈-step1-担保圈表函数

    USE [test]; GO /****** Object: UserDefinedFunction [dbo].[f_findrecycle] Script Date: 2019/7/8 14:37 ...