| Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 81322 | sh25_zhangyy | 高精度除低精度 | C++ | 通过 | 0 MS | 256 KB | 1259 | 2026-01-04 15:46:10 |
#include <iostream> #include <string> #include <algorithm> std::pair<std::string, std::string> divide(const std::string& dividend, int divisor) { if (divisor == 0) throw std::runtime_error("Division by zero"); if (dividend == "0") return {"0", "0"}; std::string quotient, remainder; std::string current; for (char digit : dividend) { current += digit; int q = 0; while (!current.empty() && std::stoll(current) >= divisor) { current = std::to_string(std::stoll(current) - divisor); ++q; } quotient += std::to_string(q); if (!current.empty()) remainder = current; } quotient.erase(0, quotient.find_first_not_of('0')); remainder.erase(0, remainder.find_first_not_of('0')); return {quotient.empty() ? "0" : quotient, remainder.empty() ? "0" : remainder}; } int main() { std::string M; int N; std::cin >> M >> N; try { auto [quotient, remainder] = divide(M, N); std::cout << quotient << "\n" << remainder << std::endl; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } return 0; }