输入:
num1 = "123456789012345678901234567890"
num2 = "987654321098765432109876543210"
输出:
"1111111110111111111011111111100"
- ✅
- 历史解析
- 整体题解思路正确,本题主要考查大整数的高精度加法,没有问题💯
输入:
num1 = "987654321098765432109876543210"
num2 = "123456789012345678901234567890"
输出:
"864197532086419753208641975320"
- ✅
- 历史解析
- 整体题解思路正确,本题主要考查大整数的高精度减法,没有问题💯
- 涉及小数值减大数值时,需要注意结果的正负问题,可以通过比较两个数值的大小,来确定结果的正负。
bool negative = false;
if (num1.length() < num2.length() || (num1.length() == num2.length() && num1.compare(num2) < 0)) {
swap(num1, num2);
negative = true;
}
if (negative) {
result = "-" + result;
}
输入:
num1 = "123456789012345678901234567890"
num2 = "987654321098765432109876543210"
输出:
"121932631137021795226185032733622923332237463801111263526900"
- ✅
- 历史解析
- 整体题解思路正确,本题主要考查大整数的高精度乘法,没有问题💯