高精度除法 t
作者:
Oct_9
,
2024-04-02 23:23:54
,
所有人可见
,
阅读 4
//自己的写法
#include <iostream>
#include <vector>
using namespace std;
vector<int> division(vector<int> a, int b)
{
vector<int> c;
int t = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
t = a[i] + t * 10;
c.push_back(t / b);
t = t % b;
}
c.push_back(t);
return c;
}
int main()
{
string a;
int b;
cin >> a >> b;
vector<int> A;
for (int i = a.length() - 1; i >= 0; i --) A.push_back(a[i] - '0');
auto ans = division(A, b);
int i = 0;
for (; i < ans.size() - 1; i ++) if (ans[i]) break;
if (i == ans.size() - 1) printf("0");
else
for (; i < ans.size() - 1; i ++) printf("%d", ans[i]);
printf("\n%d", ans.back());
return 0;
}