题目链接: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.