当前位置:网站首页>【7. 高精度除法】
【7. 高精度除法】
2022-06-22 02:32:00 【小呆鸟_coding】
高精度除法
思路:
- 高精度整数除以低精度的整数,商为C,余数为r。
- 从高位依次除以低精度整数。商存在数组中,
r * 10 + 后一位,继续除以低精度整数。一直循环结束。- 去掉前导0
步骤:
- 为了和之前的高精度加法、减法、乘法模板一致,这里也是采用倒序存储,唯一不同的点是,这里是从高位进行运算,而之前都是从低位进行运算
- 设置余数,初始值 为0,高精度整数从高位依次除以低精度整数,商存在数组中,余数 r * 10 + 后一位,继续运算。
- 进行翻转(之前高精度整数 123 + 10,倒序存放在数组中,从低位运算 321 + 01。而乘法需要从高位运算,所以需要翻转一下 )
- 去掉前导 0
- 倒序打印
举例
代码
#include <iostream> #include <vector> #include <algorithm> using namespace std; // A / b,商是C, 余数是r vector<int> div(vector<int> &A, int b , int &r) //r 是引用 { vector<int> C; r = 0; for (int i = A.size() - 1; i >= 0; i --) { r = r * 10 + A[i]; C.push_back(r / b); r %= b; } reverse(C.begin(), C.end()); //翻转数组元素 while (C.size() > 1 && C.back() ==0) C.pop_back(); //去掉前导0 return C; } int main() { string a; int b; cin >> a >> b; vector<int> A; for (int i = a.size() - 1; i >= 0; i --) A.push_back(a[i] - '0'); int r; //余数 auto C = div(A, b ,r); for (int i = C.size() - 1; i >= 0; i --) printf("%d", C[i]); cout << endl << r <<endl; }
边栏推荐
- Wechat applet film and television review and exchange platform system graduation design completion (8) graduation design thesis template
- Wechat applet film and television review and exchange platform system graduation design (1) development outline
- Transformation numérique des RH avec okr
- EMC輻射發射整改-原理案例分析
- Minecraft 1.18.2 生化8 模组 1.3版本 物品3D化+更加复杂村庄
- Neo4j 技能树正式发布,助你轻松掌握Neo4j图数据库
- 理财产品赎回确认日是什么意思?
- 微信小程序影视评论交流平台系统毕业设计毕设(5)任务书
- Wechat applet film and television comment exchange platform system graduation design completion (6) opening defense ppt
- Microblog closes publishing multiple part-time fraud information illegal accounts: how to crack down on data fraud
猜你喜欢
![[proteus simulation] INT0 and INT1 interrupt count](/img/0b/b3f5adb97046d927e501ea34deb3d9.png)
[proteus simulation] INT0 and INT1 interrupt count

EMC辐射发射整改-原理案例分析

MySQL recursively finds the tree structure. This method is very practical!

Wechat applet film and television comment exchange platform system graduation design (2) applet function

EMC輻射發射整改-原理案例分析

小孩子学什么编程?

Starting from the classification of database, I understand the graph database

Graphacademy course explanation: Fundamentals of neo4j graph data science

Chapter 21 design of pavement crack detection and identification system -- matlab deep learning practice
![[Chapter 14 image compression and reconstruction based on principal component analysis -- matlab deep learning practical case]](/img/fa/a3ff1c0213d953f7ef8a01ea7672b9.png)
[Chapter 14 image compression and reconstruction based on principal component analysis -- matlab deep learning practical case]
随机推荐
Completion of graduation design of wechat small program film and television review and exchange platform system (5) assignment
ModuleNotFoundError: No module named ‘torchvision. datasets‘; ‘ torchvision‘ is not a package
What does the redemption confirmation date of financial products mean?
Development of power plant compliance test system with LabVIEW
基于xposed框架hook使用
How does the QT program implement the default selection of a behavior in the selected listwidget
微信小程序影视评论交流平台系统毕业设计毕设(5)任务书
What does informer have
FPGA Xilinx 7 Series FPGA DDR3 hardware design rules
Qt程序怎么实现选中ListWidget中的某一行为默认选中
微信小程序影視評論交流平臺系統畢業設計畢設(4)開題報告
Chapter 24 image and video processing based on Simulink -- matlab in-depth learning and practical collation
Brief analysis of application source code of neo4j intelligent supply chain
Using OKR for HR digital transformation
Review of mathematical knowledge: triple integral
Huayang smart rushes to Shenzhen Stock Exchange: it plans to raise 400million Fosun Weiying as a shareholder
EMC radiation emission rectification - principle case analysis
带你区分几种并行
What is a neural network
Automated tools - monitoring file changes
