题解 | #数组分组#

数组分组

http://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86

while True:
    try:
        n = int(input())
        num=list(map(int,input().split()))
        lst1=[]
        lst2=[]
        others = []
        for i in num:
            if i%5==0:
                lst1.append(i)
            elif i%3==0:
                lst2.append(i)
            else:
                others.append(i)
        sum_lst1 = sum(lst1)
        sum_lst2 = sum(lst2)
        t3=sum(others)
        flag = "false"
        if sum_lst1==(sum_lst2+t3):
            print("true")
        else:
            for i in range(len(others)):
                for j in range(i+1,len(others)+1):
                    npm = sum(others[i:j])
                    new_lst1 = sum_lst1 + npm
                    new_lst2 = sum_lst2 + t3 - npm   
                    if new_lst1==new_lst2:
                        flag="true"
                        break
            else:
                print(flag)
    except:
        break
            
       
全部评论
你这种方法尽然没报错!
点赞 回复 分享
发布于 2022-05-14 19:52

相关推荐

1 1 评论
分享
牛客网
牛客企业服务