794. 高精度除法
作者:
NYfLAmE
,
2022-03-26 18:47:43
,
所有人可见
,
阅读 173
高精度除以低精度
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector <int> C;
void div(vector <int> &A, int b, int &r){
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();
}
int main()
{
string a;
cin >> a;
int b;
cin >> b;
vector <int> A;
for (int i = a.size() - 1; i >= 0; i -- ) //注意每一次处理数据是数据成员的排列顺序
A.push_back(a[i] - '0' );
int r;
div(A, b, r);
for (int i = C.size() - 1; i >= 0; i -- )
cout << C[i];
cout << endl << r << endl;//输出余数
return 0;
}