a b c(相同) d(不同)
1 2 2 1
2 3 3 4
3 5
4
5双循环实现不了,请给出代码
1 2 2 1
2 3 3 4
3 5
4
5双循环实现不了,请给出代码
解决方案 »
- 谁读过李维的<inside vcl>,发表一下意见!我不是太满意
- 这样删除一个目录,目录下有文件
- 关于复选框问题
- 定时刷新,急
- 请猛禽接分 原帖http://expert.csdn.net/Expert/topic/2368/2368797.xml?temp=.1806757
- 调用word需要放什么控件(非可视的),我看的一些例子怎么什么也没有
- DELPHI只能作数据库吗?
- 各位老师请帮忙delphi中WriteProcessMemory就是不写入。
- quick report做的报表在winnt和win2000上打印有问题
- 如何定义一个整型的数组,取得字符串长度、取得字符串左边几个字符串、取得字符串右边几个字符串的函数分别是什么呀?
- ####关于组件开发属性的相关问题,向各位求救######
- 取图出错
var
aa,bb,cc,dd: TStringList;
i,j: byte;
flag: boolean;
begin
aa:= TStringList.Create;
bb:= TStringList.Create;
cc:= TStringList.Create;
dd:= TStringList.Create; aa.Add('aa');
aa.Add('bb');
aa.Add('cc');
aa.Add('dd');
aa.Add('ee');
bb.Add('bb');
bb.Add('cc'); for i:= 0 to aa.Count-1 do
begin
flag:= false;
for j:= 0 to bb.Count-1 do
begin
if bb.Strings[j] = aa.Strings[i] then
begin
cc.Add(bb.Strings[j]);
flag:= true;
break;
end;
end;
if not flag then dd.Add(aa.Strings[i]);
end; for i:= 0 to cc.Count-1 do
begin
listbox1.Items.Add(cc.Strings[i]);
end;
for i:= 0 to dd.Count-1 do
begin
listbox2.Items.Add(dd.Strings[i]);
end;
end;
type
TIntegerArray = array of Integer;
function IsEquality(Numb: Integer; AList: TList): boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to AList.Count - 1 do
begin
if pinteger(AList[i])^ = Numb then
begin
Result := True;
Dispose(AList[i]);
AList.Delete(i);
Break;
end;
end;
end; function DoArray(a, b: TIntegerArray; var c, d: TIntegerArray): boolean;
var
i, j: Integer;
atmpList, btmpList, ctmpList, dtmpList: TList;
tmpInteger: PInteger;
begin atmpList := TList.Create;
btmpList := TList.Create;
ctmpList := TList.Create;
dtmpList := TList.Create; for i := low(a) to high(a) do
begin
new(tmpInteger); ZeroMemory(tmpInteger, sizeof(tmpInteger));
tmpInteger^ := a[i];
atmpList.Add(tmpInteger);
end; for i := low(b) to high(b) do
begin
new(tmpInteger); ZeroMemory(tmpInteger, sizeof(tmpInteger));
tmpInteger^ := b[i];
btmpList.Add(tmpInteger);
end; for i := atmpList.Count - 1 downto 0 do
begin
if IsEquality(pinteger(atmpList[i])^, btmpList) then
begin
new(tmpInteger); ZeroMemory(tmpInteger, sizeof(tmpInteger));
tmpInteger^ := pinteger(atmpList[i])^;
ctmpList.Add(tmpInteger);
end else
begin
new(tmpInteger); ZeroMemory(tmpInteger, sizeof(tmpInteger));
tmpInteger^ := pinteger(atmpList[i])^;
dtmpList.Add(tmpInteger);
end; Dispose(atmpList[i]);
atmpList.Delete(i);
end; for i := btmpList.Count - 1 downto 0 do
begin
new(tmpInteger); ZeroMemory(tmpInteger, sizeof(tmpInteger));
tmpInteger^ := pinteger(btmpList[i])^;
dtmpList.Add(tmpInteger);
Dispose(btmpList[i]);
btmpList.Delete(i);
end;
SetLength(c, ctmpList.Count);
SetLength(d, dtmpList.Count); for i := ctmpList.Count - 1 downto 0 do
begin
c[ctmpList.Count -1 - i] := pinteger(ctmpList[i])^;
Dispose(ctmpList[i]);
end;
ctmpList.Clear;
FreeAndNil(ctmpList); for i := dtmpList.Count - 1 downto 0 do
begin
d[dtmpList.Count -1 - i] := pinteger(dtmpList[i])^;
Dispose(dtmpList[i]);
end;
dtmpList.Clear;
FreeAndNil(dtmpList); atmpList.Clear;
btmpList.Clear;
FreeAndNil(atmpList);
FreeAndNil(btmpList);
end; //test
var
a, b,
c, d: TIntegerArray;
begin
SetLength(a, 6); SetLength(b, 6);
a[0] := 1; a[1] := 2; a[2] := 3; a[3] := 4; a[4] := 5; a[5] := 6;
b[0] := 4; b[1] := 5; b[2] := 6; b[3] := 7; b[4] := 8; b[5] := 9; DoArray(a, b, c, d);
ShowMessage(inttostr(length(c)));
ShowMessage(inttostr(length(d))); //要再考虑多一点a,b数组各自元素不重复.
end;
var
i,j:integer;
s,s1:string;
a:array[1..5] of String;
b:array[1..2] of String;begin
a[1]:='1';a[2]:='2';a[3]:='3';a[4]:='4';a[5]:='5';
b[1]:='2';b[2]:='4';
for i:=1 to 2 do
begin
ListBox1.Items.Clear;
for j:=1 to 5 do
begin
if b[i]=a[j] Then
begin
ListBox2.Items.Add(a[j]);
a[j]:='';
end
Else
begin end;
if a[j]<>'' Then
ListBox1.Items.Add(a[j]);
end;
end;
end;