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

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;

begin
assign(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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值