High-precision Division, I use high-precision subtraction to simulate
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>#include<string>using namespaceStd;inlineintRead () {intx=0, f=1;CharCh=GetChar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0'; returnx*F;}Const intmaxn=10000;intA[MAXN],B[MAXN],C[MAXN];void inch(intA[])//This function is used to input the input string into an int array, the angle is 0 for the length. and stored in reverse. { strings; CIN>>s; a[0]=s.length (); for(intI=1; i<=a[0];i++) a[i]=s[a[0]-i]-'0'; return ;}voidPrintintA[])//Output{ if(!a[0]) puts ("0"); Else { for(inti=a[0];i>0; i--) printf ("%d", A[i]); Puts (""); } return ;}intCompareintA[],intB[])//The comparison function, if a<b, returns 1 if a>b, returns 1 if a=b, returns 0{ if(a[0] > b[0] )return 1; if(a[0] < b[0] )return-1; for(inti=a[0];i>0; i--) { if(A[i] > B[i])return 1; Else if(A[i] < b[i])return-1; } return 0;}voidSubintA[],intB[])//High Precision Subtraction{ intflag=Compare (A, b); if(!flag) {a[0]=0;return ;} if(Flag = =1 ) { for(intI=1; i<=a[0];i++) { if(A[i] <B[i]) {A[i+1]--; A[i]+=Ten; } A[i]-=B[i]; } while(a[0] >0&&!a[a[0]]) a[0]--; } return ;}voidnumcpy (intP[],intQ[],intDet//copy p array to q array starting from Det{ for(intI=1; i<=p[0];i++) q[i+det-1]=P[i]; q[0]=p[0]+det-1; return ;}voidDivintA[],intB[],intc[]) { intTMP[MAXN]; c[0]=a[0]-b[0]+1; for(inti=c[0];i>0; i--) {memset (TMP,0,sizeof(TMP)); numcpy (B,tmp,i); while(Compare (A,TMP) >=0) {c[i]++;sub (a,tmp);}//using subtraction to simulate Division } while(c[0] >0&&!c[c[0]]) c[0]--; return ;}intMain () {inch(a),inch(b), Div (a,b,c), print (c), print (a);
"Algorithm: 1" high-precision Division