Skip to content

Instantly share code, notes, and snippets.

@02015678
Created April 9, 2015 14:09
Show Gist options
  • Save 02015678/01ee18270d2846a2804f to your computer and use it in GitHub Desktop.
Save 02015678/01ee18270d2846a2804f to your computer and use it in GitHub Desktop.
计算2个超级大数的和
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