题解 | #数组分组#递归YYDS

数组分组

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

def fun(sum3, sum5, other):

    if sum3 == sum5 and len(other) == 0:
        return True
    elif len(other) == 0:
        return False
    else:
        return fun(sum3 + other[0], sum5, other[1:]) or fun(sum3, sum5 + other[0], other[1:])


while True:
    
    try:
        n = int(input())
        num_list = list(map(int, input().split()))
        
        list3, list5, other = [], [], []
        for i in num_list:
            if i % 3 == 0:
                list3.append(i)
                continue
            if i % 5 == 0:
                list5.append(i)
                continue
            other.append(i)
        sum3 = sum(list3)
        sum5 = sum(list5)
        if fun(sum3, sum5, other):
            print('true')
        else:
            print('false')
        
        
    except:
        break
全部评论

相关推荐

爱看电影的杨桃allin春招:我感觉你在炫耀
点赞 评论 收藏
分享
5 1 评论
分享
牛客网
牛客企业服务