当前位置:网站首页>[7. high precision division]
[7. high precision division]
2022-06-22 02:41:00 【Little silly bird_ coding】
High precision division
Ideas :
- High precision integers divided by low precision integers , Shang Wei C, Remainder is r.
- Divide the high order by the low precision integer . Quotient exists in the array ,
r * 10 + The latter, Continue to divide by low precision integers . Until the cycle ends .- Remove the lead 0
step :
- In order to add with high precision 、 Subtraction 、 The multiplication template is consistent , Here, reverse order storage is also used , The only difference is , Here is the operation from the high order , Before that, the operation was carried out from the low order
- Set remainder , Initial value by 0, High precision integers are divided by low precision integers from high order , Quotient exists in the array , remainder r * 10 + The latter , Continue with the calculation .
- Flip ( Previous high-precision integers 123 + 10, Stored in the array in reverse order , Operate from the low order 321 + 01. Multiplication, on the other hand, requires high-order operations , So you need to turn it over )
- Remove the lead 0
- Print in reverse order
give an example
Code
#include <iostream> #include <vector> #include <algorithm> using namespace std; // A / b, Business is C, The remainder is r vector<int> div(vector<int> &A, int b , int &r) //r Is quoted { 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()); // Flip array elements while (C.size() > 1 && C.back() ==0) C.pop_back(); // Remove the lead 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; // remainder 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 comment exchange platform system graduation design (2) applet function
- Brief analysis of application source code of neo4j intelligent supply chain
- 【8、一维前缀和】
- C ++ Primer 第2章 变量和基本类型 总结
- MATLAB 学习笔记(4)MATLAB 数组
- 【7. 高精度除法】
- FPGA Xilinx 7 Series FPGA DDR3 hardware design rules
- C # judge whether the application is started and displayed
- Matlab learning notes (5) import and export of MATLAB data
- June25,2022 PMP Exam clearance manual-5
猜你喜欢

LabVIEW开发发电厂合规性测试系统

The brand, products and services are working together. What will Dongfeng Nissan do next?

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

Brief introduction to common pigtails of communication pigtails

Game jam development cycle

小孩子学什么编程?

如何选择合适的 Neo4j 版本(2022版)

fatal error: png++/png.hpp: 没有那个文件或目录

GraphAcademy 课程讲解:《Neo4j 图数据科学简介》

Technical exploration: 360 digital subjects won the first place in the world in ICDAR OCR competition
随机推荐
EMC辐射发射整改-原理案例分析
PMP项目管理知识该如何运用?
【一起上水硕系列】Day Two
带你区分几种并行
Get to know unity3d (project structure, third-party plug-in of probuilder)
Cmake common command category notes
Pytorch visualization
EMC輻射發射整改-原理案例分析
With the acceleration of industry wide digital transformation, what kind of storage will be more popular?
Minecraft 1.18.2 生化8 模组 1.3版本 物品3D化+更加复杂村庄
使用 OKR 进行 HR 数字化转型
Using OKR for HR digital transformation
Brief introduction to common pigtails of communication pigtails
论文笔记: 多标签学习 ACkEL
PMP pre exam guide on June 25, you need to do these well
Creating and extending XFS file system based on LVM
基于xposed框架hook使用
Paper notes: multi label learning ackel
【3.整数与浮点数二分】
How to use tensorboard add_ histogram
