var
R1: array of Integer;
R2: array of Integer;
SL1: TStringList;
SL2: TStringList;
Idx: Integer;
Index: Integer;
S1: array of Integer;
S2: array of Integer;
S3: array of Integer;
S4: array of Integer;
S5: array of Integer;
S6: array of Integer;
S7: array of Integer;
S8: array of Integer;
S9: array of Integer;
begin
Setlength(R1, 10);
SetLength(R2, 9);
R1[0] := 1;
R1[1] := 6;
R1[2] := 23;
R1[3] := 15;
R1[4] := 5;
R1[5] := 28;
R1[6] := 8;
R1[7] := 11;
R1[8] := 10;
R1[9] := 19;
R2[0] := 2;
R2[1] := 23;
R2[2] := 4;
R2[3] := 15;
R2[4] := 5;
R2[5] := 17;
R2[6] := 12;
R2[7] := 11;
R2[8] := 3;
SL1 := TStringList.Create;
SL2 := TStringList.Create;
//'%.8d'的目的有2个,
//其一是排序, 其二是满足大数据
for Idx := Low(R1) to High(R1) do
SL1.Add(Format('%.8d', [R1[Idx]]));
for Idx := Low(R2) to High(R2) do
SL2.Add(Format('%.8d', [R2[Idx]]));
//为了显示方便,我用了ListBox.
//在你的实际程序中你可以用TStringList来代替.
ListBox1.Sorted := True;
ListBox2.Sorted := True;
ListBox3.Sorted := True;
ListBox4.Sorted := True;
ListBox5.Sorted := True;
ListBox6.Sorted := True;
ListBox7.Sorted := True;
ListBox8.Sorted := True;
ListBox9.Sorted := True;
for Idx := 0 to Pred(SL1.Count) do
begin
Index := SL2.IndexOf(SL1[Idx]);
if Index < 0 then
begin
ListBox1.Items.Add(SL1[Idx]);
ListBox2.Items.Add(Format('%.8d', [Idx]));
end else
begin
ListBox5.Items.Add(SL1[Idx]);
ListBox6.Items.Add(Format('%.8d', [Idx]));
ListBox7.Items.Add(Format('%.8d', [Index]));
if Idx = Index then
begin
ListBox8.Items.Add(SL1[Idx]);
ListBox9.Items.Add(Format('%.8d', [Idx]));
end;
end;
end;
for Idx := 0 to Pred(SL2.Count) do
begin
if SL1.IndexOf(SL2[Idx]) < 0 then
begin
ListBox3.Items.Add(SL2[Idx]);
ListBox4.Items.Add(Format('%.8d', [Idx]));
end;
end;
//剩下的工作就是把Listbox ---> s数组,
//我只写一个,其余的照葫芦画瓢}
SetLength(S1, ListBox1.Items.Count);
for Idx := 0 to Pred(ListBox1.Items.Count) do
S1[Idx] := StrToInt(ListBox1.Items[Idx]);
//上面算法的前提
//1、是每个数组自身没有重复数
//2. R1的长度大于等于R2的长度
//如要满足任何条件,算法基本没有大的变化, 只是多了一个遍历
end;