pascal 高精度压位(加减乘&高精除单精)

来源:互联网 发布:歧视 美国 数据 编辑:程序博客网 时间:2024/05/01 00:55
program pro;type mine=array[0..1000000]of int64;var        s1,s2:ansistring;        n1,n2:mine;        nn,i,j:longint;procedure insert(st:ansistring; var x:mine);var        len:longint;begin        len:=length(st);        while len>=4 do        begin                inc(x[0]);                val(copy(st,len-3,4),x[x[0]]);                dec(len,4);        end;        if len>0 then        begin                inc(x[0]);                val(copy(st,1,len),x[x[0]]);        end;end;procedure plus(var a:mine; b:mine);var        ii,jj:longint;        c:mine;begin        fillchar(c,sizeof(c),0);        if a[0]<b[0] then c[0]:=b[0]        else c[0]:=a[0];        for ii:=1 to c[0] do        begin                c[ii+1]:=c[ii+1]+(c[ii]+a[ii]+b[ii])div 10000;                c[ii]:=(c[ii]+a[ii]+b[ii])mod 10000;        end;        while c[c[0]+1]>0 do inc(c[0]);        a:=c;end;procedure minus(var a:mine; b:mine);var        ii,jj:longint;        c:mine;begin        fillchar(c,sizeof(c),0);        if a[0]<b[0] then c[0]:=b[0]        else c[0]:=a[0];        for ii:=1 to c[0] do        begin                c[ii]:=c[ii]+a[ii]-b[ii];                if c[ii]<0 then                begin                        inc(c[ii],10000);                        dec(c[ii+1]);                end;        end;        while (c[0]>1)and(c[c[0]]=0) do dec(c[0]);        a:=c;end;procedure mul(var a:mine; b:mine);var        ii,jj:longint;        c:mine;begin        fillchar(c,sizeof(c),0);        c[0]:=a[0]+b[0]-1;        for ii:=1 to a[0] do        for jj:=1 to b[0] do        begin                c[ii+jj]:=c[ii+jj]+(c[ii+jj-1]+a[ii]*b[jj])div 10000;                c[ii+jj-1]:=(c[ii+jj-1]+a[ii]*b[jj])mod 10000;        end;        while c[c[0]+1]>0 do inc(c[0]);        a:=c;end;procedure divv(var a:mine; b:int64);var        ii:longint;        xx:int64;        c:mine;begin        xx:=0;        fillchar(c,sizeof(c),0);        c[0]:=a[0];        for ii:=a[0] downto 1 do        begin                c[ii]:=xx*10000+a[ii];                xx:=c[ii] mod b;                c[ii]:=c[ii] div b;        end;        while (c[0]>1)and(c[c[0]]=0)do dec(c[0]);        a:=c;end;procedure print(a:mine);var        ii:longint;begin        write(a[a[0]]);        for ii:=a[0]-1 downto 1 do        begin                if a[ii]<1000 then write(0);                if a[ii]<100  then write(0);                if a[ii]<10   then write(0);                write(a[ii]);        end;end;beginassign(input,'test.in'); reset(input);assign(output,'testyw.out'); rewrite(output);        readln(s1);        readln(s2);readln(nn);        insert(s1,n1);        insert(s2,n2);        divv(n1,nn);        print(n1);close(input);close(output);end.

0 0
原创粉丝点击