题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
def arr_group(sum3, sum5, list_temp): if len(list_temp) == 0: if sum3 == sum5: return True else: return False else: return arr_group(sum3 + list_temp[0], sum5, list_temp[1:]) or arr_group(sum3, sum5 + list_temp[0], list_temp[1:]) while 1: try: n = int(input()) num = list(map(int, input().split())) list1 = [] list2 = [] list_temp = [] for i in range(n): if num[i] % 5 == 0: list1.append(num[i]) elif num[i] % 3 == 0: list2.append(num[i]) else: list_temp.append(num[i]) sum3 = sum(list2) sum5 = sum(list1) print(str(arr_group(sum3, sum5, list_temp)).lower()) except: break