求VB算法!现有100名运动员参加100米比赛,运动员跑道数为6,将100名运动员随机分组.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 18:58:09
求VB算法!现有100名运动员参加100米比赛,运动员跑道数为6,将100名运动员随机分组.
求VB算法!现有100名运动员参加100米比赛,运动员跑道数为6,将100名运动员随机分组.
求VB算法!现有100名运动员参加100米比赛,运动员跑道数为6,将100名运动员随机分组.
N = Inputbox("请输入运动员的总人数","运动员的总人数输入对话框",100)
M = Inputbox("请输入每组人数","每组人数输入对话框",6)
Randomize '初始化随机数生成器.
upperbound = N
lowerbound = 1
K = 0
for i = 1 to upperbound
S= S & " " & i
next
do until len(S) = 0
K = K +1
DD = Split(trim(S)," ")
B=""
C=""
EE=""
if ubound(DD)>M-1 then
ww = M
elseif (ubound(DD)= 0 ) then
ww =ubound(DD) +1
end if
for i = 1 to ww
DO
mn = 0
A= Int((ubound(DD) + 1 - lowerbound + 1) * Rnd + lowerbound)
if len (B) 0 THEN
BE = split(trim(B)," ")
FOR ed = 0 to ubound(BE)
IF BE(ed)-A = 0 THEN
mn = 1
exit for
END IF
NEXT
if mn = 0 then
B = B & " " & A
EXIT DO
end if
ELSEif len (B) = 0 THEN
B = B & " " & A
EXIT DO
END IF
LOOP
next
BE = split(trim(B)," ")
FOR ed = 0 to ubound(BE)
C = C & " " & DD(BE(ed)-1)
DD(BE(ed)-1) =""
NEXT
FOR J= 0 TO ubound(DD)
if len(DD(J)) 0 then
EE = EE & " " & DD(J)
END IF
NEXT
S = EE
hy = hy & CHR(10) & CHR(10) & "第" & K & "组:" & TRIM(C)
LOOP
MSGBOX N & "人随机分组,每组" & M & "人的一种情况如下:" & CHR(10) & CHR(10) & "( 数字代表运动员号码 )" & hy ,4160 ,"SIR007_001 2012.05.10"