题解
【提高】高精度除单精度
1 条题解
-
0
#include <iostream> #include <string> #include <vector> using namespace std; string divide(string num, int divisor) { string result = ""; int remainder = 0; // 逐位处理 for (int i = 0; i < num.length(); i++) { int digit = num[i] - '0'; int current = remainder * 10 + digit; int quotient = current / divisor; remainder = current % divisor; // 只有在结果不为前导零时才添加 if (!(result.empty() && quotient == 0)) { result += to_string(quotient); } } // 如果结果为空,说明商为0 if (result.empty()) { return "0"; } return result; } int main() { string a; int b; cin >> a >> b; string quotient = divide(a, b); cout << quotient << endl; return 0; }
- 1