@w616561153
2020-01-27T23:34:01.000000Z
字数 1583
阅读 382
未分类
import sys
a = []
b = []
c = set()
cnt = int(0)
'''
for i in range(10):
s = input().split()
a.append(s)
'''
for line in sys.stdin:
s = line.split()
a.append(s)
b = a.copy()
for x in a:
if x[0][0] == 'c':
del b[int(x[1]) - 1 - cnt]
cnt += 1
for i in b:
if i[0][0] != 'c':
c.add(float(i[1]))
c.add(0.0)
c = list(c)
c.sort(reverse = True)
ans = int(0)
for i in c:
sum_buy , sum_sell = 0 , 0
for j in b:
if j[0][0] == 'b' and float(j[1]) >= i:
sum_buy += int(j[2])
if j[0][0] == 's' and float(j[1]) <= i:
sum_sell += int(j[2])
if min(sum_sell, sum_buy) > ans:
t = i
ans = min(sum_sell, sum_buy)
print("{:.2f} {}".format(t, ans))
#集合竞价
#cancel是从前往后执行的,不能取消cancel
import sys
records = []
delList=[]
for line in sys.stdin:
record = list(line.split())
records.append(record)
#根据cancel清除记录
for record in records:
if(record[0] == "cancel"):#用数组记录并del可能会删除两遍发生错误
record[0] = ""
records[int(record[1])-1][0] = ""#将要删除的记录和本条记录都清空
elif record[0] in ("buy","sell"):
record[1] = float(record[1])#价格
record[2] = int(record[2])#数量
for i in reversed(range(len(records))):#删除撤销记录
#print(i,records[i])
if(records[i][0]==""):
records.remove(records[i])
#print(records)
#构建buy,sell字典
records.sort(key=(lambda x:x[1]),reverse=True)#根据价格从大到小排序
buylist = {}
lastbuy=0
for bs,price,amount in records:
if(bs == "buy"):
lastbuy += amount
buylist[price]=lastbuy#存入字典
selllist = {}
lastsell=0
for bs,price,amount in records[::-1]:#价格从小到大
if(bs == "sell"):
lastsell += amount
selllist[price]=lastsell
#求竞价结果
prices=list(buylist)
max_amount=0
best_price = 0
for price in prices:
if(min(buylist[price],selllist[price])>max_amount):#买入和卖出两者的最小值为成交数
best_price=price
max_amount=min(buylist[price],selllist[price])#记录当前最大成交数
print("{:.2f} {}".format(best_price,max_amount))