Bryson • 9天前
不想说啥,模板题
#include <bits/stdc++.h>
using namespace std;
void zh(string s, int a[]) {
int n = s.size();
reverse(s.begin(), s.end());
for (int i = 0; i < n; i++) {
a[i] = s[i] - '0';
}
}
int a[2000], b[2000], c[2000];
int main() {
string s1, s2;
int la, lb, lc;
cin >> s1 >> s2;
zh(s1, a);
zh(s2, b);
la = s1.size();
lb = s2.size();
lc = max(la, lb);
for (int i = 0; i < lc; i++)
c[i] = a[i] + b[i];
int jw = 0;
for (int i = 0; i < lc; i++) {
c[i] = c[i] + jw;
jw = c[i] / 10;
c[i] = c[i] % 10;
}
if (jw) {
c[lc] = jw;
lc++;
}
for (int i = lc - 1; i >= 0; i--)
cout << c[i];
return 0;
}
评论:
请先登录,才能进行评论