有如下数组:[3 5 11 19 23 D
9 11 16 22 25 C
5 10 13 18 22 B
7 8 15 20 26] A用户在四个EDIT中输入0-4的整数(也可以不输完四个EDIT)就能产生一定数量
符合条件的数组比如输入1 2 就随机产生下面的: 8 10 13 19 23 (和A组有1个相同,和B组有2个相同)
如果EDIT中有0
如: 2 0 1 就产生
15 20 21 24 25 (和A组有2个相同,和B组有0个相同,和C组有1个相同)大家帮忙啊!
9 11 16 22 25 C
5 10 13 18 22 B
7 8 15 20 26] A用户在四个EDIT中输入0-4的整数(也可以不输完四个EDIT)就能产生一定数量
符合条件的数组比如输入1 2 就随机产生下面的: 8 10 13 19 23 (和A组有1个相同,和B组有2个相同)
如果EDIT中有0
如: 2 0 1 就产生
15 20 21 24 25 (和A组有2个相同,和B组有0个相同,和C组有1个相同)大家帮忙啊!
思路是这样的:
f(v: array of integer; n integer) 函数
begin
局部变量的初始化;
for i:=0 to n-1 do
begin
flag = 1; //flag=1说明随机数中有重复,应重新取值
while(flag)
begin
flag:= 0;
取随机数;
if i=0 then
begin
Compare[i]:= 随机数; //用一数组保存随机数
Str:= Str + inttostr(Temp); //Str 做为函数的返回值
end
else
begin
for j:=0 to i-1 do //判断,一旦发现重复,就要重新取随机数
begin
if 随机数=Compare[j] then
flag:= 1;
end;
end; //else
end; //while
if i<>0 then
if flag=0 then
begin
Compare[i]:= Temp; //继续保存随机数
Str:= Str + ' ' + inttostr(Temp);
end;
end; //for
end;