- BC20260009's blog
高精度除法(高精度除以低精度)
- 2024-5-5 22:07:26 @
#include <bits/stdc++.h>
using namespace std;
int main()
{
char str[1005] = {};
int b;
cin >> str >> b;
int a[1005] = {};
int la = strlen(str);
for (int i = 0 ; i < la ; i++)
{
a[i] = str[i] - 48;
}
int lans = la;
int ans[1005] = {};
int r = 0;
for (int i = 0 ; i < lans ; i++ )
{
ans[i] = ( r * 10 + a[i] ) / b;
r = ( r * 10 + a[i] ) % b;
}
int k = 0;
while (ans[k] == 0 && k < lans - 1 )
{
k++;
}
for (int i = k; i <= lans-1; i++)
{
cout << ans[i];
}
return 0;
}