@w616561153
2020-01-27T15:34:01.000000Z
字数 1583
阅读 440
未分类
import sysa = []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 += 1for 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 , 0for 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 = ians = min(sum_sell, sum_buy)print("{:.2f} {}".format(t, ans))
#集合竞价#cancel是从前往后执行的,不能取消cancelimport sysrecords = []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=0for bs,price,amount in records:if(bs == "buy"):lastbuy += amountbuylist[price]=lastbuy#存入字典selllist = {}lastsell=0for bs,price,amount in records[::-1]:#价格从小到大if(bs == "sell"):lastsell += amountselllist[price]=lastsell#求竞价结果prices=list(buylist)max_amount=0best_price = 0for price in prices:if(min(buylist[price],selllist[price])>max_amount):#买入和卖出两者的最小值为成交数best_price=pricemax_amount=min(buylist[price],selllist[price])#记录当前最大成交数print("{:.2f} {}".format(best_price,max_amount))