【基础】高精度乘法

来自本人百度空间  2009-08-20 16:48

program gaojingdu(input,output);
var
        str1,str2:string;
        a,b,c:array[1..10000] of integer;
        l1,l2,i,j,g,s,z,top:longint;
begin
        assign(input,'gaojingdu.in');
        reset(input);
        assign(output,'gaojingdu.out');
        rewrite(output);

        readln(str1);
        readln(str2);
        close(input);

        l1:=length(str1);    l2:=length(str2);
        for i:=l1 downto 1 do a[l1-i+1]:=ord(str1[i])-ord('0');
        for i:=l2 downto 1 do b[l2-i+1]:=ord(str2[i])-ord('0');
        fillchar(c,sizeof(c),0);

        s:=0;    g:=0;    z:=0;
        for i:=1 to l2 do
            for j:=1 to l1 do begin
                z:=b[i]*a[j];
                g:=z mod 10;
                s:=z div 10;
                top:=i+j-1;
                c[top]:=c[top]+g;
                c[top+1]:=c[top+1]+c[top] div 10 +s;
                c[top]:=c[top] mod 10;
            end;{jisuan}
        top:=l1+l2;
        while c[top]=0 do dec(top);
        for i:=top downto 1 do write(c[i]);
        close(output);
end.

网上一傻X竟然给错误程序

还好我脑子好使没上当~~~


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值