function AddNumStrings (Str1, Str2 : string): string;
var
i : integer;
carryStr : string;
worker : integer;
workerStr,s : string;
begin
Result := inttostr (length(Str1));
Result := '';
carryStr := '0';
// make numbers the same length
s:=StringofChar('0',Length(Str1)-1);
Str2:=s+Str2;
i := 0;
while i < length(Str1) do
begin
worker := strtoint(copy(Str1, length(str1)-i, 1)) +
strtoint(copy(Str2, length(str2)-i, 1)) +
strtoint (carryStr);
if worker > 9 then
begin
workerStr := inttostr(worker);
carryStr := copy(workerStr, 1, 1);
result := copy(workerStr, 2, 1) + result;
end
else
begin
result := inttostr(worker) + result;
carryStr := '0';
end;
inc(i);
end; { while }
if carryStr <> '0' then
result := carryStr + result;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s,z:String;
begin
s:='1000';
repeat
s:=AddNumStrings(s,'1');
until
Length(s)=1000;
ShowMessage(s);
end;
end.
但这段代码需要时间。对我的代码有什么选择以最快的方式吗? 我工作量很大,所以我必须手动编写“Inc()”程序以获得数十亿的数字。我知道你对它的看法我必须这样做。谢谢..
答案 0 :(得分:5)
希望其中一个更快......