AcWing 794. 高精度除法
原题链接
简单
作者:
现代修士o_O
,
2021-04-20 21:51:57
,
所有人可见
,
阅读 206
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> div(vector<int> &A, int &b, int &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(); // 去掉前导零
return C;
}
int main()
{
string a;
vector<int> A;
int b;
cin >> a >> b;
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;
return 0;
}