Advertisement
AlexG2230954

Untitled

May 31st, 2022
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. from collections import Counter
  2.  
  3.  
  4. actioners = dict() # словарь с данными об акционерах
  5. stocks = dict() # словарь с данными о стоимости акций
  6.  
  7.  
  8. with open("input.txt", "r") as file:
  9. command_counts = int(file.readline())
  10. lines = file.readlines()
  11.  
  12.  
  13. for line in lines:
  14. tokens = line.split()
  15. command = tokens[0]
  16.  
  17. if command == "BUY":
  18. client, company, value = tokens[1], tokens[2], int(tokens[3])
  19.  
  20. if actioners.get(client, None) is None:
  21. actioners[client] = Counter()
  22.  
  23. actioners[client].update({company: value})
  24.  
  25.  
  26. if command == "SELL":
  27. client, company, value = tokens[1], tokens[2], int(tokens[3])
  28.  
  29. if actioners.get(client, None) is None:
  30. actioners[client] = Counter()
  31.  
  32. stocks_count = actioners[client].get(company, 0)
  33. actioners[client].update({company: -min(value, stocks_count)})
  34.  
  35.  
  36. if command == "PRICE_RAISE":
  37. company, percents = tokens[1], float(tokens[2])
  38. stocks[company] = stocks.get(company, 1) * (1 + percents / 100)
  39.  
  40.  
  41. if command == "PRICE_FALL":
  42. company, percents = tokens[1], float(tokens[2])
  43. stocks[company] = stocks.get(company, 1) * (1 - percents / 100)
  44.  
  45.  
  46. if command == "BALANCE":
  47. client = tokens[1]
  48. balance = 0
  49. client_stocks = actioners.get(client, Counter())
  50.  
  51. for company, count in client_stocks.most_common():
  52. stock_price = stocks.get(company, 1)
  53. balance += stock_price * count
  54.  
  55. print(round(balance))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement