#include<iostream>
using namespace std;
string s1, s2;
int a[2100], b[2100], c[2100];
void toi_reverse(int t[], string s) {
for (int i = 0; i < s.length(); i++) {
t[s.length() - i] = s[i] - '0';
}
}
int main()
{
cin >> s1 >> s2;
toi_reverse(a, s1);
toi_reverse(b, s2);
int lena = s1.length(), lenb = s2.length();
int lenc = max(lena, lenb);
for (int i = 1; i <= lenc; i++)
{
c[i] = a[i] + b[i] + c[i];
if (c[i] >= 10)
{
c[i + 1]++;
c[i] %= 10;
if (i == lenc) {
lenc++;
}
}
}
while (c[lenc] == 0 && lenc > 1)lenc--;
for (int i = lenc; i >= 1; i--)
{
cout << c[i];
}
return 0;
}
高精度加法
最新推荐文章于 2024-08-30 16:00:44 发布