Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- actioners = dict() # словарь с данными об акционерах
- stocks = dict() # словарь с данными о стоимости акций
- with open("input.txt", "r") as file:
- command_counts = int(file.readline())
- lines = file.readlines()
- for line in lines:
- tokens = line.split()
- command = tokens[0]
- if command == "BUY":
- client, company, value = tokens[1], tokens[2], int(tokens[3])
- if actioners.get(client, None) is None:
- actioners[client] = Counter()
- actioners[client].update({company: value})
- if command == "SELL":
- client, company, value = tokens[1], tokens[2], int(tokens[3])
- if actioners.get(client, None) is None:
- actioners[client] = Counter()
- stocks_count = actioners[client].get(company, 0)
- actioners[client].update({company: -min(value, stocks_count)})
- if command == "PRICE_RAISE":
- company, percents = tokens[1], float(tokens[2])
- stocks[company] = stocks.get(company, 1) * (1 + percents / 100)
- if command == "PRICE_FALL":
- company, percents = tokens[1], float(tokens[2])
- stocks[company] = stocks.get(company, 1) * (1 - percents / 100)
- if command == "BALANCE":
- client = tokens[1]
- balance = 0
- client_stocks = actioners.get(client, Counter())
- for company, count in client_stocks.most_common():
- stock_price = stocks.get(company, 1)
- balance += stock_price * count
- print(round(balance))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement