#include <bits/stdc++.h>
using namespace std;
int a[1001], b[1001], c[1001];
int main() {
string s1, s2;
cin >> s1 >> s2;
int l1 = s1.size();
int l2 = s2.size();
for (int i = 0; i < l1; i++){
a[i] = s1[l1 - 1 - i] - '0';
}
for (int i = 0; i < l2; i++){
b[i] = s2[l2 - 1 - i] - '0';
}
int l = max(l1,l2);
for (int i = 0; i < l; i++) {
c[i] += a[i] + b[i];
if (c[i] >= 10) {
c[i + 1] = 1;
c[i] %= 10;
}
}
if (c[l] == 1){
l++;
}
int k = l--;
while (c[k] == 0 && k > 0){
k--;
}
for (int i = k; i >= 0; i--){
cout << c[i];
}
return 0;
}
高精度加法
最新推荐文章于 2024-09-13 16:27:15 发布