zoukankan      html  css  js  c++  java
  • Automatches

    import os
    
    def combine(ArrayList,count):
        ArrayList=list(ArrayList)
        newArrayList=[]
        for i in range(0,ArrayList.__len__()-count+1):
            LackArray=ArrayList
            CurrentValue=LackArray[i]
            for tube in range(i+1,ArrayList.__len__()-count+2):
                TotalValue=CurrentValue
                Process=str(i)
                newArray={}
                for c in range(0,count-1):
                    index=tube+c
                    TotalValue=TotalValue+LackArray[index]
                    Process=Process+"+"+str(index)
    
                newArray[str(TotalValue)]=Process
                newArrayList.append(newArray)
        return newArrayList
    
    
    def generateAll(ArrayList):
        All=[]
        for i in range(2,ArrayList.__len__()+1):
            All=All+combine(ArrayList,i)
    
        return All
    
    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
    
    
    
    
    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]
        print(moretimes(a,b))
        # print(getArrayList("1.txt"))
        # b=[6,10,15]
    
        # print(generateAll(a))
        # print(generateNewLackArray(a,3,b))
  • 相关阅读:
    [Jenkins] 批量删除构建历史
    [Android Tips] 32. 解决 Android Device Monitor 在 Mac OS X 卡住
    [Gradle] 查看项目依赖
    [Gradle] 获取 gradle 命令行参数
    [Android Tips] 31.如何将第三库引入的 Permission 删除掉
    [Gradle] 发布构件到本地仓库
    [Android Tips] 30.如何在 Android Studio 中一次性格式化所有代码
    下载安卓应用的历史版本
    设置int、float型数据的输出格式
    头文件limits—各个类型的数据的范围
  • 原文地址:https://www.cnblogs.com/Zeech-Lee/p/11695820.html
Copyright © 2011-2022 走看看