Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- clients = defaultdict(lambda: defaultdict(int))
- stocks = defaultdict(lambda: 1)
- def buy_action(client, company, value):
- clients[client][company] += value
- def sell_action(client, company, value):
- amount = clients[client][company]
- clients[client][company] -= min(value, amount)
- def balance_check(client):
- return sum(stocks[company] * amount for company, amount in clients[client].items())
- def price_raise(company, percents):
- stocks[company] *= (1 + percents / 100)
- def price_fall(company, percents):
- stocks[company] *= (1 - percents / 100)
- handlers = {
- "BUY" : lambda args: buy_action(args[0], args[1], int(args[2])),
- "SELL" : lambda args : sell_action(args[0], args[1], int(args[2])),
- "PRICE_RAISE" : lambda args : price_raise(args[0], float(args[1])),
- "PRICE_FALL" : lambda args : price_fall(args[0], float(args[1])),
- "BALANCE" : lambda args: print(round(balance_check(args[0])))
- }
- n = int(input())
- for _ in range(n):
- cmd, *args = input().split()
- handlers[cmd](args)
Add Comment
Please, Sign In to add comment