#include
四、高精度除法 4.1、高精度除以低精度
for (int i = 0; i < x.size(); i++) {c[i] = (tmp * 10 + a[i]) / y;tmp = (tmp * 10 + a[i]) % y;}
算法原理用手写,说不清楚 。
#include
4.2、高精度除以高精度
int compare(int a[], int b[])//比较a和b的大小关系,若a>b则为1,a b[0]) return 1;//a的位数大于b则a比b大 if (a[0] < b[0]) return -1;//a的位数小于b则a比b小 for (i = a[0]; i > 0; i--)//从高位到低位比较 {if (a[i] > b[i]) return 1;if (a[i] < b[i]) return -1;}return 0;//各位都相等则两数相等 。}void numcpy(int p[], int q[], int n)//复制p数组到q数组从det开始的地方{for (int i = 1; i <= p[0]; i++) q[i + n - 1] = p[i];q[0] = p[0] + n - 1;}void jian(int a[], int b[])//计算a=a-b{int flag, i;flag = compare(a, b);//调用比较函数判断大小 if (flag == 0) { a[0] = 0; return; }//相等 if (flag == 1)//大于{for (i = 1; i <= a[0]; i++){if (a[i] < b[i]) { a[i + 1]--; a[i] += 10; }//若不够减则向上借一位 a[i] -= b[i];}while (a[0] > 0 && a[a[0]] == 0) a[0]--;//修正a的位数 return;}}void HighDiv(string x, string y) {int a[LENGTH], b[LENGTH], c[LENGTH];memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));memset(c, 0, sizeof(c));a[0] = x.length();for (int i = 1; i <= a[0]; i++)a[i] = x[a[0] - i] - '0';b[0] = y.length();for (int i = 1; i <= b[0]; i++)b[i] = y[b[0] - i] - '0';int tmp[101];c[0] = a[0] - b[0] + 1;for (int i = c[0]; i > 0; i--) {memset(tmp, 0, sizeof(tmp));numcpy(b, tmp, i);while (compare(a, tmp) >= 0) {c[i]++; jian(a, tmp); }}while (c[0] > 0 && c[c[0]] == 0)c[0]--;for (int i = c[0] ; i > 0; i--)printf("%d", c[i]);printf("\n");}
- 336个幽默成语之“最”大合集, 有趣又好记!给孩子收藏细读 世界之最成语
- 清朝太监用什么方法防死后被掘坟?
- P5730 【深基5.例10】显示屏 - 字符表问题
- 徐昭佩是谁?萧绎只得徐妃半面妆的故事
- 秦始皇陵迷之地宫:受高人指点构建江河湖海
- 上 html5+css3学习
- 配柴油2.0升动力,欧马可S1新小卡能拉1.8吨货,售价9.66万起 柴油轻卡汽车大全
- 新款帕萨特正式上市,卖17.99万元起!共13款车型,就问你香不香? 上海大众车型大全图片
- task2 【南瓜书ML】线性模型的数学推导(最小二乘估计、广义瑞利商、极大似
- 【一起入门MachineLearning】中科院机器学习-期末题库