#include <iostream>
#include <cmath>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string A, B;
cin >> A >> B;
int len = max(A.size(), B.size());
int a[len], b[len], res[len + 1];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(res, 0, sizeof(res));//初始化,声明在全局区可以省去这一步
for (int i = A.size() - 1, j = 0; i >= 0; i--, j++) {
a[j] = A[i] - '0';
}
for (int i = B.size() - 1, j = 0; i >= 0; i--, j++) {
b[j] = B[i] - '0';
}
for (int i = 0; i < len; i++) {
res[i] += a[i] + b[i];
res[i + 1] = res[i] / 10;
res[i] %= 10;
}
if (res[len]) {
len++;
}
for (int i = len - 1; i >= 0; i--) {
cout << res[i];
}
cout << endl;
}
高精度加法
最新推荐文章于 2022-07-28 23:43:22 发布