UVa OJ 424-Integer Inquiry

    技术2024-10-04  58

    高精:

    { Author:wzx961008 Problem:UVa 424-Integer Inquiry Verdict:Accepted Language:PASCAL Run Time:0.004s Submission Date:2011-02-03 15:23:17 } var sum,n:string; function HighPlus(s1,s2:string):string; var a,b,c:array[1..103]of integer; lena,lenb,lenc,i,x:integer; begin HighPlus:=''; fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); fillchar(c,sizeof(c),0); lena:=length(s1); lenb:=length(s2); for i:=1 to lena do a[lena-i+1]:=ord(s1[i])-ord('0'); for i:=1 to lenb do b[lenb-i+1]:=ord(s2[i])-ord('0'); i:=1; x:=0; while (i<=lena)or(i<=lenb) do begin x:=a[i]+b[i]+x div 10; c[i]:=x mod 10; inc(i); end; if x>=10 then begin lenc:=i; c[i]:=1 end else lenc:=i-1; for i:=lenc downto 1 do HighPlus:=HighPlus+chr(c[i]+48); end; begin sum:='0'; while true do begin readln(n); if n='0' then break; sum:=HighPlus(sum,n); end; writeln(sum); end.

    最新回复(0)