请回答下列问题:
随机选取n个圆盘,其半径与颜色分别存储在列表r和color中并输出,如图b所示,
r = [9,3,6,4,8,5], color = ['红','紫','蓝','绿','橙','红']。
n = 1en(r)
f= { } # f中键为颜色,值为该颜色的可见数量,如: {" 蓝":2}
def pop(top, cnum, rad):
while top!= -1 and rad >= r[z[top]]:
f[color[z[top]]] -= 1
if ①
cnum -= 1
top -= 1
return top, cnum
z=[-1]*n
top = -1
cnum=cmax=0
for i in range(n):
top, cnum = pop(top, cnum, p[i])
top += 1
②
if color[z[top]] not in f:
if[color[z[top]]= 1
cnum+= 1
else :
f[color[z[top]] += 1
if cnum >= cmax:
cmax = cnum
res = dict(f) #将此时的f另存到res中
m= ③
s=""
for i in res:
if res[i] > 0:
s +=i
print("拿走", m, "片后,可看到圆盘的颜色种数最多,分别为: ", s)
①②③