Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
75630 sh25_shenpy 高精度减法 C++ 编译错误 0 MS 0 KB 737 2025-12-08 19:00:54

Tests(0/0):


std::string subtractLargeNumbers(const std::string& a, const std::string& b) { std::string result; int carry = 0; int i = a.size() - 1, j = b.size() - 1; while (i >= 0 || j >= 0 || carry != 0) { int digitA = (i >= 0) ? a[i] - '0' : 0; int digitB = (j >= 0) ? b[j] - '0' : 0; int diff = digitA - digitB - carry; if (diff < 0) { diff += 10; carry = 1; } else { carry = 0; } result.push_back(diff + '0'); i--; j--; } // 修复前导零 while(result.size() > 1 && result.back() == '0') result.pop_back(); std::reverse(result.begin(), result.end()); return result; }


测评信息: