AcWing 794. 高精度除法-31ms-c++
原题链接
简单
作者:
二月
,
2019-10-31 10:29:05
,
所有人可见
,
阅读 1351
时间复杂度o(n)
c++代码
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// res = A / b, r = A % b;
string div(const string& A, const int& b, int& r)
{
string res;
for (int i = 0; i < A.size(); i++)
{
r = r * 10 + (A[i] - '0');
res += (r / b) + '0';
r %= b;
}
while (res.size() > 1 && res.front() == '0') res = res.substr(1);
return res;
}
int main ()
{
ios::sync_with_stdio(false);
string A;
int b;
cin >> A >> b;
int r = 0;
cout << div(A, b, r) << endl;
cout << r << endl;
return 0;
}
你的代码写的好美~