var x,y:ansistring; a,b:array[1..11000]of int64; c:array[1..35000]of int64; num:array[1..11000] of longint; i,j,lena,lenb,lenc,len:longint; procedure init; begin fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); fillchar(c,sizeof(c),0); end; function compare(s1:string;s2:string):boolean; var len1,len2:longint; begin len1:=length(s1); len2:=length(s2); if ((len1<len2)or(len1=len2) and (s2>s1))then compare:=true else compare:=false; end; procedure input; begin readln(x); len:=length(x); lena:=len div 5; for i:=1 to len do num[i]:=ord(x[len-i+1])-48; for i:=1 to lena do a[i]:=num[5*i]*10000+num[5*i-1]*1000+num[5*i-2]*100+num[5*i-3]*10+num[5*i-4]; if ((len mod 5)<>0) then begin inc(lena); for i:=1 to (len mod 5) do a[lena]:=a[lena]*10+num[len-i+1]; end; readln(y); len:=length(y); lenb:=len div 5; for i:=1 to len do num[i]:=ord(y[len-i+1])-48; for i:=1 to lenb do b[i]:=num[5*i]*10000+num[5*i-1]*1000+num[5*i-2]*100+num[5*i-3]*10+num[5*i-4]; if ((len mod 5)<>0) then begin inc(lenb); for i:=1 to (len mod 5) do b[lenb]:=b[lenb]*10+num[len-i+1]; end; end; procedure print; begin write(c[lenc]); for i:=lenc-1 downto 1 do begin if (c[i] = 0) then write(‘00000‘) else if (c[i]<10) then write(‘0000‘,c[i]) else if (c[i]<100) then write(‘000‘,c[i]) else if (c[i]<1000) then write(‘00‘,c[i]) else if (c[i]<10000) then write(‘0‘,c[i]) else write(c[i]); end; end; procedure plus; begin fillchar(c,sizeof(c),0); if (lena>lenb) then lenc:=lena+1 else lenc:=lenb+1; for i:=1 to lenc do begin c[i]:=a[i]+b[i]+c[i]; c[i+1]:=c[i+1]+c[i] div 100000; c[i]:=c[i] mod 100000; end; while ((c[lenc]=0) and (lenc<>1)) do dec(lenc); print; end; procedure mui; begin fillchar(c,sizeof(c),0); for i:=1 to lena do for j:=1 to lenb do c[i+j-1]:=c[i+j-1]+a[i]*b[j]; for i:=1 to lena+lenb-1 do if (c[i]>9999) then begin c[i+1]:=c[i+1]+c[i] div 100000; c[i]:=c[i] mod 100000; end; lenc:=lena+lenb; while ((c[lenc]=0) and (lenc<>1)) do dec(lenc); print; end; procedure sub; begin fillchar(c,sizeof(c),0); if compare(x,y) then begin write(‘-‘); for i:=1 to lenb do begin b[i]:=b[i]-a[i]; b[i+1]:=b[i+1]+ord(b[i]>=0)-1; b[i]:=b[i]+ord(b[i]<0)*100000; c[i]:=b[i]; end; lenc:=lenb; end else begin for i:=1 to lena do begin a[i]:=a[i]-b[i]; a[i+1]:=a[i+1]+ord(a[i]>=0)-1; a[i]:=a[i]+ord(a[i]<0)*100000; c[i]:=a[i]; end; lenc:=lena; end; while ((c[lenc]=0) and(lenc>1)) do dec(lenc); print; end; procedure division; begin 1.正向存入数组2.一直比较试除,直到最后一位(要改大框架,所以就直接说思想了)end; //main begin while not eof do begin init; input; plus; writeln; sub; writeln; mui; writeln; end; end.
时间: 2024-10-14 03:28:14