Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_comb(price: int, count: int, step=0):
- if step == 0 and (price < 1 or count < 1) or price < 0 and count < 0:
- raise ValueError('Цена и количество монет должны быть натуральными числами!')
- price -= step
- if count == price == 0:
- if price + count > 0:
- return price + step, count + 1
- return 0, 0
- if price >= 25:
- price, count = check_comb(price, count - 1, 25)
- if count > 0 and price >= 10:
- price, count = check_comb(price, count - 1, 10)
- if count > 0 and price >= 5:
- price, count = check_comb(price, count - 1, 5)
- if count > 0 and price >= 1:
- price, count = check_comb(price, count - 1, 1)
- if step == 0:
- if price + count > 0:
- return False
- return True
- if price + count > 0:
- return price + step, count + 1
- return 0, 0
- if __name__ == '__main__':
- price = int(input('Искомая сумма в центах\n'))
- count = int(input('Количество монет\n'))
- res = check_comb(price, count)
- if res:
- print('Можно')
- else:
- print('Нельзя')
Add Comment
Please, Sign In to add comment