比如有一堆不规则的数字,一个数字占一行
1
3
4
8
11
3
1
45
34
8
……
怎么计算出这些数字有几种不同的数字?因为特殊原因,不能动用到数据库,就只能用delphi语言计算,我逻辑思维不强,想了一会没想出来,希望各位指教,如果方便最好能给出相应代码,谢谢了。
1
3
4
8
11
3
1
45
34
8
……
怎么计算出这些数字有几种不同的数字?因为特殊原因,不能动用到数据库,就只能用delphi语言计算,我逻辑思维不强,想了一会没想出来,希望各位指教,如果方便最好能给出相应代码,谢谢了。
procedure TForm1.Button1Click(Sender:TObject);
var
str:TStringList;
i, n, memoi, memon:Integer;
spth, s, sid,ceshistr,ceshistr2:string;
cf:Boolean;begin
Self.Memo1.Text:='';
if Self.dlgOpen1.Execute then
begin
spth:= Self.dlgOpen1.FileName;
end;
str:= TStringList.Create;
str.Add('');
str.LoadFromFile(spth);
s:= str.Text;
// ShowMessage(s);
str.Free;
n:= Length(s) div 16; for i:= 0 to n - 1 do
begin
sid:= Copy(s, 16 * i + 1, 16);
if sid <> '0000000000000000' then
begin
Memo1.Lines.Add(sid);
end;
end;
memoi:= Memo1.Lines.Count;
//ShowMessage('高总这个ID.TXT的数量是: '+IntToStr(Memo1.Lines.Count)+' 个');
// ShowMessage(Memo1.Lines[0]);
cf:=False;
memon:=1;
for i:= 0 to memoi-1 do
begin
n:=1;
while n<=i do
begin
if Memo1.Lines[i]=Memo1.Lines[i-n] then
begin
cf:=False;
ceshistr:=ceshistr+#13+Memo1.Lines[i];
Break;
end;
if Memo1.Lines[i]<>Memo1.Lines[i-n] then
begin
cf:=True;
ceshistr2:=ceshistr+#13+Memo1.Lines[i];
end; n:=n + 1;
end;
if cf=True then
begin
memon:=memon+1; end;
end;
zzsl.Text:= IntToStr(memon)+' 个'; str:= TStringList.Create;
str.Add(ceshistr);
str.SaveToFile('D:\1.txt');
str.Free;
str:= TStringList.Create;
str.Add(memo1.Text);
str.SaveToFile('D:\2.txt');
str.Free;
//ShowMessage(inttostr(memo1.Lines.Count));
//ShowMessage('这个TXT的数量是: ' + IntToStr(memon) + ' 个');
end;