高精度加法

2021-04-13 11:49:31 字數 823 閱讀 7944

program gjplus;

vars1,s2,s3,st,s:string;

i,j,k,l1,l2,li,n1,n2,n3,n4:integer;

begin

readln(s1);

readln(s2);

l1:=length(s1);

l2:=length(s2);

if l1>l2 then li:=l1 else li:=l2;

n4:=0;

for i:=1 to li do begin

if i<=l1 then val(copy(s1,(l1+1-i),1),n1,j) else n1:=0;// writeln(n1);

if i<=l2 then val(copy(s2,(l2+1-i),1),n2,j) else n2:=0;// writeln(n2);

n3:=n1+n2+n4;

if n3>=10 then begin

n4:=n3 div 10;

n3:=n3 mod 10;

end else n4:=0;

str(n3,st);

insert(st,s3,256-i);

end;

//output

k:=length(s3);

li:=0;

for i:=1 to k do begin

val(copy(s3,k-i+1,1),j);

if j>0 then li:=li+1;

if li>0 then write(j);

end;

readln;

end.

python高精度加法 高精度加法

1.思路 其實就是模擬,加法是最簡單的,從個位開始加,價位加到前一位,然後再取10的餘數。for int i 1 i len i 計算和 c i a i b i 進製 c i 1 c i 10 取10的餘數 c i 10 2.實現 int len max a.length b.length 倒著存,...

高精度加法 高精度減法

雖然以前自己就學習過,但是自己打出來的 目測效率不高,也不夠精簡 因此學習一下eden裡面的這一題 big integer add subtract ifndef big integer define big integer include include using std string usin...

高精度加法

整形的範圍有限,計算的數字不能滿足現實中遇到的一些 大數 解決辦法是將數字存到陣列中,在陣列中對應運算最後取出即可 下面 include include int add int a,int b if a i h i 保留位數 return h int main b 200 int clen strl...