高精度
2014-10-28 21:53
309 查看
高精度是基本知识,先从简单到难
最基本:
1.高精度加法(高精度数加高精度数)
3.高精度乘法
4.高精度数除以高精度数的整数部分(须挪用前面三个函数)
最基本:
1.高精度加法(高精度数加高精度数)
</pre><pre name="code" class="html"><span style="font-size:18px;">function jia(t1,t2:string):string; var a,b,c:arr;//程序定义时写:type arr=array[1..1000]of integer; x,i,max:longint;//x:进位标记 begin fillchar(a,sizeof(a),0);b:=a; for i:=1 to length(t1) do a[length(t1)-i+1]:=ord(t1[i])-ord('0'); for i:=1 to length(t2) do b[length(t2)-i+1]:=ord(t2[i])-ord(‘0’); if length(t1)>length(t2) then max:=length(t1) else max:=length(t2); x:=0; for i:=1 to max do begin c[i]:=a[i]+b[i]+x; x:=c[i] div 10; c[i]:=c[i] mod 10; end; if x>0 then begin inc(max);c[max]:=x; end; jia:=''; for i:=max downto 1 do jia:=jia+chr(c[i]+ord('0')); end;</span>2.高精度减法(高精度数减高精读数)
<span style="font-size:18px;">function jian(t1,t2:string):string var a,b,c:arr;//程序定义时写:type arr=array[1..1000]of integer; i,max:longint; t:string;//交换 begin if (length(t1)<length(t2))or((length(t1)=length(t2))and(t1<t2)) then begin jian:='-';t:=t1;t1:=t2;t2:=t; end else jian:=''; fillchar(a,sizeof(a),0);b:=a; for i:=1 to length(t1) do a[length(t1)-i+1]:=ord(t1[i])-ord('0'); for i:=1 to length(t2) do b[length(t2)-i+1]:=ord(t2[i])-ord('0'); if length(t1)>length(t2) then max:=length(t1) else max:=length(t2); for i:=1 to max do begin c[i]:=a[i]-b[i]; if c[i]<0 then begin c[i]:=c[i]+10;dec(a[i+1]); end; end; while (max>1)and(c[max]=0) do dec(max); for i:=max downto 1 do jian:=jian+chr(c[i]+ord('0')); end;</span>稍微有点麻烦:
3.高精度乘法
<span style="font-size:18px;"><span style="color:#362e2b;">function cheng(t1,t2:string):string; var a,b,c:arr;//程序定义时写:type arr=array[1..1000]of integer; x,i,j,w:longint;//x:进位标记 w:位数 begin fillchar(a,sizeof(a),0);b:=a; c:=a; for i:=1 to length(t1) do a[length(t1)-i+1]:=ord(t1[i])-ord('0'); for i:=1 to length(t2) do b[length(t2)-i+1]:=ord(t2[i])-ord('0'); for i:=1 to length(t1) do begin x:=0; for j:=1 to length(t2) do begin c[i+j-1]:=a[i]*b[j]+x+c[i+j-1]; x:=c[i+j-1] div 10; c[i+j-1]:=c[i+j-1] mod 10; end; c[i+j]:=x; end; w:=length(t1)+length(t2); while (c[w]=0)and(w>1) do dec(w); cheng:=''; for i:=w downto 1 do cheng:=cheng+chr(c[i]+ord('0')); end;</span></span>可以为普及组第三题或第四题,提高组第二题或第三题,即使会方法,打程序的时候都易出错的:
4.高精度数除以高精度数的整数部分(须挪用前面三个函数)
<span style="font-size:18px;"><span style="color:#362e2b;">function chu(p1,t2:ansistring):ansistring; var s1:array[0..9]of ansistring; ws:array[1..9]of longint; i,wi,wt2,wt1,x,t,fw:longint; shi,t1,f:ansistring; function cha(f1,f2:ansistring):longint; var i,wf1,w:longint; begin wf1:=length(f1); for i:=1 to 9 do begin w:=length(s1[i]); if (w>wf1)or((w=wf1)and(s1[i]>f1)) then begin cha:=i-1; break; end; end; end; begin t1:=p1;wt1:=length(t1);wt2:=length(t2); chu:=''; s1[0]:='0'; for i:=1 to 9 do begin s1[i]:=cheng(t2,chr(i+ord('0'))); ws[i]:=length(s1[i]); end; shi:='';i:=1; while (i<=wt1) do begin shi:=shi+t1[i]; t:=cha(shi,t2); chu:=chu+chr(t+ord('0')); if t<>0 then begin delete(t1,1,i); f:=jian(shi,s1[t]); if f<>'0' then begin t1:=f+t1; shi:=f;i:=length(f); end else begin shi:='';i:=0; end; wt1:=length(t1); end; inc(i); end; while chu[1]='0' do delete(chu,1,1); end;</span></span>
相关文章推荐
- poj2109 高精度+二分
- POJ 1001 求高精度幂
- A+B Problem II(高精度运算)
- [xenclient] 使用总结 ---centos 下使用高精度的console控制台
- 自己写的一个高精度加法,网上有的都太高深,我本身是新手,写的大概新手比较好懂
- ACM-ZOJ 1086 八进制小数转十进制 低位高精度除法初步认识
- 高精度
- (高精度) Octal Fractions (P1131)
- 高精度模板总结1(string 实现加、减、乘、除)常用版 kuangbin
- 高精度定时器在mips上的框架结构
- 2010年华为上机笔试二(高精度整数加法)
- UVa 10523 高精度
- 高精度 两小数相加
- 二分法+高精度——Poj 2109 Power of Cryptography(double型开n次方的方法通过的原因)
- C++高精度实现计算程序运行时间
- hdu - 1042 - N!(高精度计算)
- hdu 1753 坑爹的高精度
- ACM题目:求高精度幂C++解法
- 高精度之求N!
- POJ-1001 Exponentiation 高精度