求大神帮我看看,高精度加法压位到底哪里错了

学术版

//刚刚发现了一些错误,改过来啦,请大家帮忙指正// by2.0版 ```cpp Program ex_39; Var a,b,c:array[1..255] of integer; s,temp:string; i,len,temp2,k:longint; Begin Fillchar(a,sizeof(a),0); Fillchar(b,sizeof(b),0); readln(s); temp:=s; len:=length(s); if len mod 4 <>0 then begin s:='0'; For i:=1 to (4-(len mod 4)-1) do s:=s+'0'; s:=s+temp; end; len:=len+4-(len mod 4); For i:=len downto 1 do begin if i mod 4=0 then begin temp:=s[i-3]+s[i-2]+s[i-1]+s[i]; Val(temp,a[len-i+1]); end; end; readln(s); temp:=s; len:=length(s); if len mod 4 <>0 then begin s:='0'; For i:=1 to (4-(len mod 4)-1) do s:=s+'0'; s:=s+temp; end; len:=len+4-(len mod 4); For i:= len downto 1 do begin if i mod 4=0 then begin temp:=s[i-3]+s[i-2]+s[i-1]+s[i]; Val(temp,b[len-i+1]); end; end; k:=0; For i:=1 to 255 do c[i]:=a[i]+b[i]; For i:=255 downto 1 do if (c[i]>=10000) or ((c[i]+k)>=10000) then begin temp2:=c[i]; c[i]:=k+c[i] mod 10000; k:=temp2 div 10000; end; k:=0; For i:=255 downto 1 do begin if c[i]<>0 then k:=1; if k=1 then write(c[i]); end; readln; end. ```
by Niscet @ 2016-11-27 22:08:01


@[汪添翼](/space/show?uid=24617) 把数组开大些试试吧,还有字符串也开大些,反正内存多的是,128MB你根本用不完
by huhuhuhaha @ 2016-11-27 22:32:32


```cpp var a,b,c:array[1..500] of longint; n,m:string; i,ln,lm,l:longint; begin readln(n); ln:=length(n); for i:=1 to ln do a[ln-i+1]:=ord(n[i])-48; readln(m); lm:=length(m); for i:=1 to lm do b[lm-i+1]:=ord(m[i])-48; if ln>lm then l:=ln else l:=lm; for i:=1 to l+1 do c[i]:=0; for i:=1 to l do begin c[i]:=c[i]+a[i]+b[i]; if c[i]>=10 then begin c[i+1]:=c[i+1]+c[i] div 10; c[i]:=c[i] mod 10; end; end; if c[l+1]<>0 then l:=l+1; for i:=l downto 1 do write(c[i]); end. ``` 这个 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
by mr辄 @ 2016-11-28 11:31:11


@[汪添翼](/space/show?uid=24617) hehehe
by zhych @ 2016-11-28 12:22:13


谢谢大家的帮助!!!我的问题已经解决辣~\(≧▽≦)/~
by Niscet @ 2016-11-28 13:11:14


@ zhych !!!
by Niscet @ 2016-11-28 13:13:12


@[zhych](/space/show?uid=8756) !!!!!
by Niscet @ 2016-11-28 13:13:51


@[汪添翼](/space/show?uid=24617) eeeeee
by zhych @ 2016-11-28 13:17:05


|