本帖最后由 Stubborn 于 2019-10-27 17:06 编辑 def depot(a, b, c):
def _check_b(a: dict, b: dict, c: dict) -> bool:
"""b的数量小于a才能被取出"""
def no_gods(key):
if c.get(key, False):
return "Impossible"
return False
for key, value in b.items():
res = a.get(key, False)
if not res:
return no_gods(key)
if res - value < 0:
# {需要的物品单词} {如果 A 要满足 B 的需求需要进货的最少数量} 进货不满足是这样返回吗?
return f"{key}{value - res}"
return True
def _check_c(a: dict, c: dict):
"""所有的商品,都应该能从c取出"""
for key, value in a.items():
res = c.get(key, False)
if not res:
return False
return True
def to_dict(A: list):
dic = {}
for value in A:
if value not in dic:
dic.setdefault(value, 1)
else:
dic[value] += 1
return dic
dict_a = to_dict(a.split(' '))
dict_b = to_dict(b.split(' '))
dict_c = to_dict(c.split(' '))
return _check_b(dict_a, dict_b, dict_c), _check_c(dict_a, dict_c)
|