基本思路
该除法基本思想是模拟竖式除法,其中被除数是高精度,除数是低精度,要注意除数不能为0。
高精度除以低精度
#include<bits/stdc++.h>
using namespace std;
const int N = 100090;
int a[N],b,c[N];
int main()
{
string x;
int len,reminder=0;//余数使用前一定要初始化
memset(a,0,sizeof(a));//使用前要初始化
memset(c,0,sizeof(c));
cin >> x >> b;
if(b==0){
cout << "除数不能为0" << endl;
return 0;
}
len = x.length();
for(int i=0;i<len;i++)
{
a[i] = x[len-1-i]-'0';
}//将被除数字符串转化整型,注意在数组a中顺序做了颠倒
for(int i=len-1;i>=0;i--)
{
reminder = reminder*10+a[i];
c[i] = reminder/b;
reminder %= b;
} //模拟竖式除法
while(c[len]==0&&len>0) len--;//除去数组c中多余的前缀0
for(int i=len;i>=0;i--) cout << c[i];//输出商
cout << endl << reminder;//输出余数
cout << endl;
return 0;
}