您的位置:首页 > 其它

UVa OJ 748-Exponentiation

2011-02-09 20:57 197 查看
高精:

{
Author:wzx961008
Problem:UVa 748-Exponentiation
Verdict:Accepted
Language:PASCAL
Run Time:0.016s
Submission Date:2011-02-09 12:55:02
}
var s:string[9];
base,ans:ansistring;
pt,ps,pp,i,m:longint;
function HighMultiply(s1,s2:ansistring):ansistring;
var a,b,c:array[1..10000]of integer;
lena,lenb,lenc,i,j,x:integer;
begin
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
fillchar(c,sizeof(c),0);
HighMultiply:='';
lena:=length(s1); lenb:=length(s2);
for i:=1 to lena do a[lena-i+1]:=ord(s1[i])-ord('0');
for i:=1 to lenb do b[lenb-i+1]:=ord(s2[i])-ord('0');
for i:=1 to lena do begin
x:=0;
for j:=1 to lenb do begin
x:=a[i]*b[j]+x div 10+c[i+j-1];
c[i+j-1]:=x mod 10;
end;
c[i+j]:=x div 10;
end;
lenc:=i+j;
while (c[lenc]=0)and(lenc>1) do dec(lenc);
for i:=lenc downto 1 do HighMultiply:=HighMultiply+chr(c[i]+48);
end;
begin
while not eof do begin
readln(s);
ps:=pos(' ',s);
if s[ps+1]<>' ' then m:=(ord(s[ps+1])-48)*10+(ord(s[ps+2])-48)
else m:=ord(s[ps+2])-48;
pp:=pos('.',s);
for i:=ps downto pp do begin
if (s[i]>='1')and(s[i]<='9') then break;
if s[i]='0' then delete(s,i,1);
end;
pt:=(i-pp)*m;
base:='';
for i:=1 to i do
if s[i]<>'.' then base:=base+s[i];
ans:=base;
for i:=1 to m-1 do
ans:=HighMultiply(ans,base);
while pt>length(ans) do
ans:='0'+ans;
insert('.',ans,length(ans)-pt+1);
writeln(ans);
end;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: