#coding=utf-8
from random import choice
vanguards = ['sl','qb','zy','lf','wc','gh','wl','xy','yt','sln'] #前锋人员
guards =[] #后卫
almighty =[] #全能,既能做后卫也能做前锋
result = {}
print "报名人数:",len(vanguards)
#print "后卫报名人数:",len(guards)
#print "全能人员人数:",len(almighty)
print "共可组成:",(len(vanguards)+len(guards)+len(almighty))/2,"队"
def team(La,Lb):
while (len(La) and len(Lb)) > 0:
vanguard = choice(La)
La.remove(vanguard)
guard = choice(Lb)
Lb.remove(guard)
result[vanguard] = guard
return max(La,Lb)
def team2(Lc):
while len(Lc) > 1:
p1 = choice(Lc)
Lc.remove(p1)
p2 = choice(Lc)
Lc.remove(p2)
result[p1] = p2
if Lc != []:
print "剩下",Lc,"没组队"
first1 = team(vanguards,guards) # 前锋和后卫先组队
if first1 == []:
team2(almighty)
else:
secd = team(first1,almighty)# 剩下的前锋或者后卫和全能组队
if secd !=[]:
team2(secd) #最后组内的互相组队
i=1
for k,v in result.items():
print i,"---",k,"和",v
i+=1
根据报名人员,让他们随机组队
最新推荐文章于 2022-11-28 17:34:07 发布