「NOIP2017模拟赛08.02」A**B

   题目链接:http://hhhoj.ngrok.cc/contest/3/problem/4

   高精度乘法

   小数点位数加一下就好了

   注意前后的0以及输出规范

   贴代码

 type arr=array[0..300]of longint;
 var s:string;
     n,x,bo,i,j,t,len,bo1:longint;
     ans,a:arr;
 function mul(a,b:arr):arr;
  var i,j:longint;
      var c:arr;
   begin
    fillchar(c,sizeof(c),0);
    c[0]:=a[0]+b[0]-1;
    for i:=1 to a[0] do
     for j:=1 to b[0] do
      begin
       inc(c[i+j-1],a[i]*b[j]);
       inc(c[i+j],c[i+j-1]div 10);
       c[i+j-1]:=c[i+j-1]mod 10;
      end;
    if c[c[0]+1]>0 then inc(c[0]);
    exit(c);
   end;
begin
// assign(input,'1.in');reset(input);
// assign(output,'1.out');rewrite(output);
 readln(s);
 if s[1]='.' then s:='0'+s;
 x:=pos(' ',s);
 bo:=0;val(copy(s,x+1,length(s)-x),n);
 for i:=1 to x-1 do if s[i]='.' then bo:=i;
 if bo<>0 then bo:=(x-1-bo)*n;
 while s[1]='0' do delete(s,1,1);
 len:=x-1;
 if s[1]='.' then delete(s,1,1);
 x:=pos(' ',s);
 len:=x-1;bo1:=0;
 for i:=1 to len do if s[i]='.' then bo1:=1;
 if bo1=1 then dec(len);
 i:=len;j:=1; a[0]:=len;
 while i>=1 do
  begin
   if s[j]='.' then inc(j);
   a[i]:=ord(s[j])-48;
   dec(i);inc(j);
  end;
 ans[0]:=1;ans[1]:=1;
 for t:=1 to n do ans:=mul(ans,a);
 if bo>=ans[0] then begin
                    write('.');
                    for i:=1 to bo-ans[0] do write('0');
                    for i:=ans[0] downto 1 do write(ans[i]);
                   end
               else begin
                     for i:=1 to ans[0]-bo do write(ans[ans[0]-i+1]);
                     if bo<>0 then write('.');
                     for i:=ans[0]-i downto 1 do write(ans[i]);
                    end;
 // close(input);close(output);
 end.

【写的有漏洞的,欢迎路过大神吐槽】

  2017/08/02 22:03:29

  Ending. 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值