POJ 1001 Exponentiation

心血来潮花了一上午做了这道恶心死人的高精度。展示一下打了各种补丁的程序。

type gj=record
      len:longint;
      data:array[1..1000]of longint;
     end;
const num:array[0..3]of integer=(1,10,100,1000);
var x,ans:gj;
    c:char;
    s:string;
    n,i,len,L:longint;
    flag:boolean;
procedure change(var x:gj);
var i,j:longint;
begin
  j:=0;
  fillchar(x.data,sizeof(x.data),0);
  for i:=len downto 1 do
   begin
   if (len-i)mod 4=0 then inc(j);
   x.data[j]:=x.data[j]+(ord(s[i])-48)*num[(len-i)mod 4];
   end;
  x.len:=j;
end;
function mul(a,b:gj):gj;
var i,j:longint;
begin
 fillchar(mul.data,sizeof(mul.data),0);
 for i:=1 to a.len do
  for j:=1 to b.len do
   begin
    inc(mul.data[i+j-1],a.data[i]*b.data[j]);
    inc(mul.data[i+j],mul.data[i+j-1] div 10000);
    mul.data[i+j-1]:=mul.data[i+j-1]mod 10000;
   end;
 if mul.data[i+j]>0 then mul.len:=i+j else mul.len:=i+j-1;
end;
procedure print(m:gj;t:longint);
var i,k,b,e:longint;
    w:ansistring;
begin
 W:='';
 for i:=m.len downto 1 do
  BEGIN
  w:=w+chr(48+m.data[i]div 1000);
  m.data[i]:=m.data[i]mod 1000;
  w:=w+chr(48+m.data[i]div 100);
  m.data[i]:=m.data[i]mod 100;
  w:=w+chr(48+m.data[i]div 10);
  m.data[i]:=m.data[i]mod 10;
  w:=w+chr(48+m.data[i]);
  end;
 b:=0;
 for i:=1 to length(w) do
  if w[i]<>'0' then break else b:=i;
 delete(w,1,b);
 e:=0;
 for i:=length(w) downto 1 do
  if w[i]<>'0' then break else inc(e);
 delete(w,length(w)-e+1,e);
 t:=t-e;
 if t<0 then
   begin
   for i:=1 to abs(t) do w:=w+'0';
   t:=0;
   end;
 if length(w)=0 then begin write(0);exit end;
 if t=0 then begin write(w);exit;end;
 if length(w)<=t then
  begin
   write('.');
   for i:=1 to t-length(w) do
   write('0');
   write(w);
  end
  else
   begin
   for i:=1 to length(w)-t do
    write(w[i]);
   write('.');
   for i:=length(w)-t+1 to length(w) do
    write(w[i]);
    end;
end;
begin
 while not eof do
  begin
  len:=0;L:=0;
  read(c);flag:=true;
  while (c<='9')and(c>='0') do
   begin
   if flag and(c='0') then begin read(c);continue end else flag:=false;
   inc(len);
   s[len]:=c;
   read(c);
   end;
  if c<>' ' then read(c);
  while c<>' ' do
   begin
   inc(L);
   s[len+L]:=c;
   read(c)
   end;
  inc(len,L);
  readln(n);
  if n=0 then begin writeln(1);continue end;
  change(x);
  ans:=x;
  for i:=1 to n-1 do
   ans:=mul(ans,x);
  print(ans,n*L);
  writeln
 end;
end.
posted on 2011-11-10 13:32  YY_More 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yymore/archive/2011/11/10/2244351.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值