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的更多相关文章
随机推荐
- Window Position
IE, Safari, Opera, and Chrome all provide screenLeft and screenTop properties that indicate the wind ...
- ubuntu go 开发环境搭建
访问:https://golang.org/dl/ 下载 go1.12.4.linux-amd64.tar.gz wget https://dl.google.com/go/go1.12.4.linu ...
- 【POJ - 3984】迷宫问题(dfs)
-->迷宫问题 Descriptions: 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 ...
- 1137. N-th Tribonacci Number(Memory Usage: 13.9 MB, less than 100.00% of Python3)
其实思路很简单,套用一下普通斐波那契数列的非递归做法即可,不过这个成绩我一定要纪念一下,哈哈哈哈哈 代码在这儿: class Solution: def tribonacci(self, n: int ...
- UOJ46 玄学
题目 一个比较自然的想法是线段树维护二进制分组. 因为我们询问的是一段连续的操作的积,所以我们可以建一棵线段树,每个节点存储当前区间各个操作的积. 这里的操作的积指的是把一系列操作做完之后区间每个位置 ...
- 2019年8月23日 星期五(Workerman)
Workerman,高性能socket服务框架 Workerman是什么? Workerman是一款纯PHP开发的开源高性能的PHP socket 服务框架. Workerman不是重复造轮子,它不是 ...
- PB中的DataStore的应用示例
编程过程中想在窗口中加一个下拉列表(DDLB),原来听同学说过可以动态改变下拉列表的值,数据库中的表改变,前台客户端的下拉列表就会变,记得当时同学说的是用一个叫下拉数据窗口(DDDW)的东西做的,一直 ...
- redis的string和list
- redis 学习(1)-- redis 安装与启动
redis 学习(1)-- redis 安装与启动 redis 特性 关于 redis 的介绍网上已经有很多信息了,这里我就不在详细说明了.介绍一下几个鲜明特性: 1.速度快 官方称可以达到10W的q ...
- 最小生成树之Prim Kruskal算法(转)
最小生成树 首先,生成树是建立在无向图中的,对于有向图,则没有生成树的概念,所以接下来讨论的图均默认为无向图.对于一个有n个点的图,最少需要n-1条边使得这n个点联通,由这n-1条边组成的子图则称为原 ...