POJ 1001 (坑爹的小数高精度乘法)
来源:互联网 发布:手机app监控软件 编辑:程序博客网 时间:2024/05/01 14:52
小数高精度乘法
program P1001;Type arr=record a:array[1..10000] of longint; len:longint; xs:longint; end;Var s:ansistring; n,i,j,k,len:longint; r:arr;Procedure relax(var c:arr);var i,j:longint;begin while (c.a[c.len]=0) and (c.len>1) do dec(c.len); if (c.len=1) and (c.a[1]=0) then begin c.xs:=0; exit; end; i:=1; while (c.a[i]=0) do inc(i); dec(i); if (i>0) then begin if (c.xs>=i) then dec(c.xs,i) else begin i:=c.xs; c.xs:=0; end; for j:=i+1 to c.len do c.a[j-i]:=c.a[j]; dec(c.len,i); end;end;procedure prin(c:arr);var i:longint;begin relax(c); if (c.xs=0) then begin for i:=c.len downto 1 do write(c.a[i]); writeln; exit; end; if (c.xs<=c.len) then begin for i:=c.len downto c.xs+1 do write(c.a[i]); write('.'); for i:=c.xs downto 1 do write(c.a[i]); writeln; exit; end; write('.'); for i:=1 to c.xs-c.len do write('0'); for i:=c.len downto 1 do write(c.a[i]); writeln;end;Procedure cheng(a:arr;b:arr;var c:arr);var i,j:longint;begin fillchar(c,sizeof(c),0); for i:=1 to a.len do for j:=1 to b.len do begin inc(c.a[i+j-1],a.a[i]*b.a[j]); inc(c.a[i+j],c.a[i+j-1] div 10); c.a[i+j-1]:=c.a[i+j-1] mod 10; end; c.len:=a.len+b.len+1; c.xs:=a.xs+b.xs; relax(c);end;procedure jie(a:arr;b:longint;var c:arr);begin if (b=1) then c:=a else if (b mod 2=0) then begin jie(a,b div 2,c); cheng(c,c,c); end else begin jie(a,b div 2,c); cheng(c,c,c); cheng(c,a,c); end;end;Begin while (not(eof)) do begin readln(s); len:=length(s); i:=pos(' ',s); j:=pos('.',s); if j=0 then begin r.xs:=0; r.len:=i-1; for k:=1 to r.len do r.a[r.len-k+1]:=ord(s[k])-48; end else begin r.xs:=i-j-1; r.len:=i-2; for k:=1 to j-1 do r.a[r.len-k+1]:=ord(s[k])-48; for k:=j+1 to i-1 do r.a[r.len-k+2]:=ord(s[k])-48; end; relax(r); i:=len; while (s[i]<>' ') do dec(i); n:=0; for k:=i+1 to len do n:=n*10+ord(s[k])-48; jie(r,n,r); prin(r); end;end.
- POJ 1001 (坑爹的小数高精度乘法)
- poj 1001 uva 748 Exponentiation(高精度小数乘法)
- POJ 2390 (小数高精度乘法)
- poj 1001 高精度乘法
- POJ 1001 高精度乘法
- 小数高精度乘法
- 高精度乘法(小数)
- POJ 1001 高精度乘法运算
- poj 1001 (Exponentiation) 高精度乘法
- 【POJ】 1001-Exponentiation 【高精度乘法】
- POJ 1001 Exponentiation 高精度乘法
- poj 1001 Exponentiation 高精度乘法
- POJ 1001(高精度乘法)
- POJ 1001(高精度乘法 java的2种解法)
- HDU 1063 / PKU 1001 (小数高精度乘法,JAVA写的)
- POJ 1001 Exponentiation 高精度小数相乘
- poj 1001 Exponentiation(高精度乘法)
- POJ 1001 Exponentiation (高精度/大数乘法)
- MVC学习九:ASP.NET MVC 2:模型验证
- linux下客户端检测服务器的 heartbeat
- JavaBean到XML和JSON的转换
- Linux下查看文件和文件夹大小的df和du命令
- samba配置的经历
- POJ 1001 (坑爹的小数高精度乘法)
- C#开发在VS2010开发环境里显示代码行数
- 深入浅出谈存储:如何区别NAS、SAN与DAS
- chorme App 开发笔记-----本地化
- 分页查询
- 网友举报动物园被曝用活狗喂虎 动物园称系误会
- Bluetooth的Security概述
- POJ 2154 Color Ploya定理
- omap-pand-3.0 tickless bug及解决方案