var J: Integer; I: Integer; begin with TStringList.Create do try LoadFromFile('input.txt'); //载入文件 Sort; //排序 J := 1; for I := Count - 1 downto 0 do begin if (I >= 1) and (Strings[I] = Strings[I - 1]) then begin Inc(J); Delete(I); end else begin Strings[I] := Format('(%5d)%s', [J, Strings[I]]); J := 1; end; end; Sort; //排序//取最后三行 SaveToFile('C:\temp\output.txt'); finally Free; end; end;
var J: Integer; I: Integer; begin with TStringList.Create do try LoadFromFile('input.txt'); //载入文件 Sort; //排序 J := 1; for I := Count - 1 downto 0 do begin if (I >= 1) and (Strings[I] = Strings[I - 1]) then begin Inc(J); Delete(I); end else begin Strings[I] := Format('(%5d)%s', [J, Strings[I]]); J := 1; end; end; Sort; //排序//取最后三行 SaveToFile('C:\temp\output.txt'); finally Free; end; end;
刚才没事做,帮你写了一个,带有注释function StrToIP(IP:String):DWORD; asm mov edi,10 mov esi,IP xor ecx,ecx xor ebx,ebx @nextNumber://next number in IP ddress cmp ecx,4//IPv4 :) je @end //finished push ecx xor ecx,ecx xor eax,eax @next: //next digit mov cl,byte ptr [esi] cmp cl,0 je @exit cmp cl,'.' je @exitLoop //finished processing one number sub cl,'0' mul edi add eax,ecx inc esi jmp @next @exitLoop: pop ecx shl ebx,8 add ebx,eax inc ecx inc esi jmp @nextPart @end: //reverse order mov ecx,ebx shr ecx,16//high bytes and ebx,$ffff//low bytes //exchange xchg cl,ch xchg bl,bh shl ebx,16 or ebx,ecx//combinate mov eax,ebx end;
支持导入到数据库,不就1万数据?一个access表就解决了。
总行数: //其中函数参数s为文本文件的绝对地址: 在程序中调用举例: var s :string; if form1.OpenDialog1.Execute then begin s :=form1.OpenDialog1.FileName; edit1.text :=inttostr(hangshu(s)); end; ********************************************* function TForm1.hangshu(s: string): integer; var fff :textfile; line :string; n :integer; begin n :=0; assignfile(fff,s); reset(fff); while not eof(fff) do begin readln(fff,line); if trim(line)<> '' then begin n :=n+1; end; end; closefile(fff); result :=n; end;
J: Integer;
I: Integer;
begin
with TStringList.Create do try
LoadFromFile('input.txt'); //载入文件
Sort; //排序
J := 1;
for I := Count - 1 downto 0 do begin
if (I >= 1) and (Strings[I] = Strings[I - 1]) then begin
Inc(J);
Delete(I);
end else begin
Strings[I] := Format('(%5d)%s', [J, Strings[I]]);
J := 1;
end;
end;
Sort; //排序//取最后三行
SaveToFile('C:\temp\output.txt');
finally
Free;
end;
end;
J: Integer;
I: Integer;
begin
with TStringList.Create do try
LoadFromFile('input.txt'); //载入文件
Sort; //排序
J := 1;
for I := Count - 1 downto 0 do begin
if (I >= 1) and (Strings[I] = Strings[I - 1]) then begin
Inc(J);
Delete(I);
end else begin
Strings[I] := Format('(%5d)%s', [J, Strings[I]]);
J := 1;
end;
end;
Sort; //排序//取最后三行
SaveToFile('C:\temp\output.txt');
finally
Free;
end;
end;
ffwin() ( )
没法说你,
1W多条,满不满那
IP"127:183:21:77" -->转成整形量1271832177
Sort
.....
asm
mov edi,10
mov esi,IP
xor ecx,ecx
xor ebx,ebx
@nextNumber://next number in IP ddress
cmp ecx,4//IPv4 :)
je @end //finished push ecx
xor ecx,ecx
xor eax,eax
@next: //next digit
mov cl,byte ptr [esi]
cmp cl,0
je @exit
cmp cl,'.'
je @exitLoop //finished processing one number
sub cl,'0'
mul edi
add eax,ecx
inc esi
jmp @next
@exitLoop:
pop ecx
shl ebx,8
add ebx,eax
inc ecx
inc esi
jmp @nextPart
@end:
//reverse order
mov ecx,ebx
shr ecx,16//high bytes
and ebx,$ffff//low bytes
//exchange
xchg cl,ch
xchg bl,bh
shl ebx,16
or ebx,ecx//combinate
mov eax,ebx
end;
//其中函数参数s为文本文件的绝对地址:
在程序中调用举例:
var
s :string;
if form1.OpenDialog1.Execute then
begin
s :=form1.OpenDialog1.FileName;
edit1.text :=inttostr(hangshu(s));
end;
*********************************************
function TForm1.hangshu(s: string): integer;
var
fff :textfile;
line :string;
n :integer;
begin
n :=0;
assignfile(fff,s);
reset(fff);
while not eof(fff) do
begin
readln(fff,line);
if trim(line)<> '' then
begin
n :=n+1;
end;
end;
closefile(fff);
result :=n;
end;
IP"127:183:21:77" -->转成整形量1271832177
请问"127:183:2:177"和"127:183:21:77"有什么区别?~~to Eastunfail:
你的代码编译不过呀~~to all:
10000条数据,我的算法在我的机器执行时间为300毫秒左右~~
转换成数值,存放到数据库里处理确实快!~~
请问:转换成数值、存放到数据库里需要多少时间??~~
楼主没出来,这个问题我就不继续了~~
asm
mov edi,10
mov esi,IP
xor ecx,ecx
xor ebx,ebx
@nextNumber://next number in IP ddress
cmp ecx,4//IPv4 :)
je @end //finished
push ecx
xor ecx,ecx
xor eax,eax
@next: //next digit
mov cl,byte ptr [esi]
cmp cl,0
je @exitLoop
cmp cl,'.'
je @exitLoop //finished processing one number
sub cl,'0'
mul edi
add eax,ecx
inc esi
jmp @next
@exitLoop:
pop ecx
shl ebx,8
add ebx,eax
inc ecx
inc esi
jmp @nextNumber
@end:
//reverse order
mov ecx,ebx
shr ecx,16//high bytes
and ebx,$ffff//low bytes
//exchange
xchg cl,ch
xchg bl,bh
shl ebx,16
or ebx,ecx//combinate
mov eax,ebx
end;