Created
April 9, 2015 14:09
-
-
Save 02015678/01ee18270d2846a2804f to your computer and use it in GitHub Desktop.
计算2个超级大数的和
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lena,lenb,len,i:integer; | |
s1,s2:string[101]; | |
a,b,c:array[1..101]of integer; | |
ch:char;begin s1:=''; | |
Repeat | |
read(ch); | |
IF ch<>' ' THEN s1:=s1+ch; | |
Until ch=' '; | |
readln(s2); | |
lena:=length(s1); lenb:=length(s2); | |
for i:=1 to lena do | |
a[i]:=ord( s1[lena-(i-1)] )-48; | |
for i:=1 to lenb do | |
b[i]:=ord( s2[lenb-(i-1)] )-48; | |
if lena>=lenb | |
then len:=lena | |
else len:=lenb; | |
for i:=1 to len do | |
c[i]:=a[i]+b[i]; | |
for i:=1 to len do | |
if c[i]>9 then | |
begin | |
c[i+1]:=c[i+1]+1; | |
c[i]:=c[i] mod 10; | |
end; | |
IF c[len+1]<>0 THEN write(c[len+1]); | |
for i:=len downto 1 do | |
write(c[i]); | |
writeln; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment