背景:在做CCF试题 2014-12-3题:集合竞价时出现的问题
用代码块功能插入代码,请勿粘贴
```python
lst=[]
while 1:
instruction=list(map(str,input().split())) #将输入的字符按照空格拆分成若干元素并存入一个小[]列表中
if instruction[0]=="cancel" and lst!=[]: #当小列表首位元素为cancel,且大列表不为空时,
lst.pop(int(instruction[1])-1) #从大列表中清除cancel原字符指令中所指代的第n次栈入
elif instruction[0]!="cancel": #当指令不为cancel时
lst.append(instruction) #将小列表instruction存入大列表lst中
print(lst)
lst2=lst #将列表lst赋值给列表lst2
lst2.sort() #对列表2内部进行排序
print(lst2)
```截图
运行结果:
按照四次输入:
a.buy 2.0 200
b.sell 1.5 300
c.buy 3.0 300
d.sell 4.0 400
其结果分别为:
a.[['buy', '2.0', '200']]
[['buy', '2.0', '200']]
b.[['buy', '2.0', '200'], ['sell', '1.5', '300']]
[['buy', '2.0', '200'], ['sell', '1.5', '300']]
c.[['buy', '2.0', '200'], ['sell', '1.5', '300'], ['buy', '3.0', '300']]
[['buy', '2.0', '200'], ['buy', '3.0', '300'], ['sell', '1.5', '300']]
d.[['buy', '2.0', '200'], ['buy', '3.0', '300'], ['sell', '1.5', '300'], ['sell', '4.0', '400']]
[['buy', '2.0', '200'], ['buy', '3.0', '300'], ['sell', '1.5', '300'], ['sell', '4.0', '400']]