求个算法

才子鸣 2012-03-28 11:36:28
一个数组里的数据是这样的.
1
2
3
4
2
3
1
6
7

用for从第一个往下找
需要找到第5行的时候,发现2在之前出现过.就跳过去继续找下一条,
到第6行时发现3之前也出现过,那继续下一条,
到第8行的时候,发现6之前没有,那么把这个6取出来.
依此类推....

...全文
64 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kaikai_kk 2012-03-28
  • 打赏
  • 举报
回复
这样?
t := TStringList.Create;
for I := 0 to BM.BillDetails.Count-1 do
begin
if t.indexof(BM.BillDetails.Items[i]._ItemID)<>-1 then
begin
continue;//如果相邻的两个是一样的话,这个方法可以,但有可能就是两个不相邻!
end;
t.add(BM.BillDetails.Items[i]._ItemID);
end;
才子鸣 2012-03-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);
var a:array of Integer;
t:TStringList;
i:integer;
begin
t := TStringList.Create;
SetLength(a,9);
a[0]:= 1;
a[1] :=……
[/Quote]


不好意思.没有说清楚.
是一个在TObjectList<T>里
T是一个类,有N个字段,
比如T.ID,T.Name,等等.
BillDetails : TObjectList<TRec_billdetail>;


for I := 0 to BM.BillDetails.Count-1 do
begin
if (tmpType = BM.BillDetails.Items[i]._ItemID) then
begin
continue;//如果相邻的两个是一样的话,这个方法可以,但有可能就是两个不相邻!
end;
tmpType := BM.BillDetails.Items[i]._ItemID;
end;

我看见佛 2012-03-28
  • 打赏
  • 举报
回复
1
2
3
4
6
7
结果
我看见佛 2012-03-28
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
var a:array of Integer;
t:TStringList;
i:integer;
begin
t := TStringList.Create;
SetLength(a,9);
a[0]:= 1;
a[1] := 2;
a[2] := 3;
a[3] := 4;
a[4] := 2;
a[5] := 3;
a[6] := 1;
a[7] := 6;
a[8] := 7;
for i := 0 to Length(a) - 1 do
begin
if t.IndexOf(IntToStr(a[i])) = - 1 then
t.Add(IntToStr(a[i]));
end;
Memo1.Text := t.Text;
t.Free;
end;

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧