Python
- 32 ответа
- 0 вопросов
20
Вклад в тег
month = int(input())
seasons = {0:'зима', 1:'весна', 2:'лето', 3:'осень', 4:'зима'}
if 1 <= month <= 12: print(seasons[month//3])
else: print('error')
seasons = ['зима', 'весна', 'лето', 'осень', 'зима']
from itertools import combinations
def ungroup(data_list, limit):
data_list.sort()
result_list = []
while sum(data_list) > limit:
series = [data_list.pop()]
rest = limit - series[0]
if rest == 0:
result_list.append(series)
elif rest in data_list:
result_list.append(series + [data_list.pop(data_list.index(rest))])
else:
sublist = data_list.copy()
for i in data_list:
if i > rest:
sublist = data_list[:data_list.index(i)]
break
for n in range(2, len(sublist)):
comb = {sum(i): i for i in combinations(sublist, n)}
if rest in comb.keys():
series.extend(comb[rest])
for i in comb[rest]: data_list.remove(i)
break
result_list.append(series)
if len(data_list) > 0:
result_list.append(data_list)
return result_list
print(ungroup([6, 4, 4, 3, 2, 1.5, 1, 0.5], 6))
# [[6], [4, 2], [4, 0.5, 1.5], [1, 3]]