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()”过程。我知道你怎么想,但我必须这么做。谢谢..
-
INT128 http://www.lazarus.freepascal.org/index.php/topic,17273.15.htmlFPC 的库
-
GNURZ http://forge.lazarusforum.de/projects/show/gnurzlib(用于 FPC 但应与 Delphi 兼容)
-
GMP https://gmplib.org/#DOC (FPC 支持它 http://wiki.freepascal.org/gmp、德尔福)
-
BigInt http://delphiforfun.org/programs/Math_Topics/Pell%20and%20Continued%20Fractions.htm and BigFloat http://delphiforfun.org/programs/Math_Topics/Pell%20and%20Continued%20Fractions.htm
- BigInt Delphi 库 http://sourceforge.net/projects/bigint-dl/
- Another BigInt http://www.idogendel.com/docs/projects/BigInt.zip
- TPMath http://www.unilim.fr/pages_perso/jean.debord/tpmath/tpmath.htm
-
DeHL https://code.google.com/p/delphilhlplib/对于德尔福
-
大数字 https://github.com/rvelthuis/BigNumbersDelphi 的 BigInteger、BigDecimal 和 BigRational
希望其中之一会更快......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)