标签:
1 var 2 s1,s2:string; 3 procedure plus(s1,s2:string); 4 var 5 a,b,c:array[1..500]of longint; 6 i,j1,j2,l,k,p,code:longint; 7 begin 8 fillchar(a,sizeof(a),0); 9 fillchar(b,sizeof(b),0); 10 fillchar(c,sizeof(c),0); 11 j1:=0; l:=length(s1); 12 while l>0 do 13 begin 14 inc(j1); 15 val(copy(s1,l-3,4),a[j1],code); 16 s1:=copy(s1,1,l-4); l:=length(s1); 17 end; 18 j2:=0; l:=length(s2); 19 while l>0 do 20 begin 21 inc(j2); 22 val(copy(s2,l-3,4),b[j2],code); 23 s2:=copy(s2,1,l-4); l:=length(s2); 24 end; 25 if j1>j2 then p:=j1 else p:=j2; 26 k:=0; 27 for i:=1 to p do 28 begin 29 c[i]:=a[i]+b[i]+k; 30 k:=c[i] div 10000; 31 c[i]:=c[i] mod 10000; 32 end; 33 if k=1 then 34 begin 35 inc(p); inc(c[p]); 36 end; 37 write(c[p]); 38 for i:=p-1 downto 1 do 39 begin 40 if c[i]<10 then write(‘000‘,c[i]) else 41 if c[i]<100 then write(‘00‘,c[i]) else 42 if c[i]<1000 then write(‘0‘,c[i]) else 43 write(c[i]); 44 end; 45 writeln; 46 end; 47 begin 48 readln(s1); 49 readln(s2); 50 plus(s1,s2); 51 end.
标签:
原文地址:http://www.cnblogs.com/vacation/p/5024225.html