总行数:
//其中函数参数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;
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;
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;