• 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("
    ")
            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>
    
    
    
     
  • 相关阅读:
    Java并发(十八):阻塞队列BlockingQueue
    web前端
    python学习总结:目录
    Django -- 5.路由层(URLconf)_基于Django1
    python:linux下字符串转换为JSON
    python:一秒中启动一个下载服务器
    Flask【第十二章】:Flask之Websocket,建立单聊群聊
    Flask【第十一章】:Flask中的CBV以及偏函数+线程安全
    Flask【第十章】:特殊装饰器 @app.before_request 和 @app.after_request 以及@app.errorhandler
    Flask【第九章】:Flask之蓝图
  • 原文地址:https://www.cnblogs.com/Zeech-Lee/p/11698448.html
Copyright © 2020-2023  润新知