怎么在一个数字数组中寻找另一个数组中各个数据的位置的
a[]={1.2,3.4,4.0,4.4,5.3,6.3,7,7.45,.......,100} n个数,double类型b[]={4.0,7,...,80} m个数,double类型 m<n 寻找b数组元素在a数组中的位置或者最相近数的位置b数组中的数最大不大于a数组中的数,且high(a)<high(b)
a[]={1.2,3.4,4.0,4.4,5.3,6.3,7,7.45,.......,100} n个数,double类型b[]={4.0,7,...,80} m个数,double类型 m<n 寻找b数组元素在a数组中的位置或者最相近数的位置b数组中的数最大不大于a数组中的数,且high(a)<high(b)
解决方案 »
- 请教:gmail的smtp端口,465和587的问题
- delphi 如何实现 dxDBGrid 增删查改数据
- 调用WebService,传递的汉字字符串参数乱码
- 我用delphi做了个cab的控件,怎么样才能让ie流览时下载它,并让它能正常使用?
- 请大家关注“各位高手,请问谁有通用客户或供应商管理系统的例子吗?(100分)”急!!!
- 奇怪!为什么quickReport上的元件不可以隐藏?
- 在delphi中如何跟踪sql?
- 谁知道哪儿有支持认证的SMTP组件下载?
- 用delphi的兄第快来帮忙。小弟在线等待。分不够还可以加感谢!!!
- 一个初学者的问题
- TPerlRegEx 一个工程正常,另一个出现DDC L4077 错误。怎么解决
- delphi XE2 正版价格要多少钱?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Memo2: TMemo;
Memo3: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
var a:array[0..100]of double;
b:array[0..100]of double;{$R *.dfm}//随机产生a、b两组数:
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
tmp:double;
t:boolean;
begin
Randomize;//初始化
for i:=0 to 100 do begin
while true do begin
tmp:=random(100)+random(10)/10;
t:=true;
for j:=0 to i-1 do begin
if a[j]=tmp then begin
t:=false;
break;
end;
end;
if t then begin
a[i]:=tmp;
break;
end;
end;
end;
for i:=0 to 100 do begin
while true do begin
tmp:=random(89)+random(10)/10;
t:=true;
for j:=0 to i-1 do begin
if b[j]=tmp then begin
t:=false;
break;
end;
end;
if t then begin
b[i]:=tmp;
break;
end;
end;
end;
for i:=0 to 100 do begin
memo1.Lines.Append(floattostr(a[i]));
memo2.Lines.Append(floattostr(b[i]));
end;
end;//查找b组数在a组最接近的数的位置:
procedure TForm1.Button2Click(Sender: TObject);
var i,x:integer;
d,f:double;
t:boolean;
begin
for i:=0 to 100 do begin
f:=0;
t:=true;
x:=-1;
while true do begin
if t then begin
d:=b[i]+f;
t:=false;
end
else begin
d:=b[i]-f;
f:=f+0.1;
t:=true;
end;
x:=memo1.Lines.IndexOf(floattostr(d));
if x>=0 then break;
end;
memo3.Lines.Append(inttostr(x));//显示在 a 组的位置(0为第一个)
end;
end;end.