#include <iostream>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;
int main() {
string Lu, Hui, Zheng, Yi;
stack<int> q;
while (cin >> Lu >> Hui && EOF) {
int l1 = Lu.length() - 1, l2 = Hui.length() - 1;
if (l1 >= l2) {
Yi = Lu;
Zheng = Lu;
for (int i = 0; i <= l1 - l2; i++)
Yi[i] = '0';
for (int i = l1 - l2, j = 0; j <= l2; j++, i++)
Yi[i] = Hui[j];
for (int i = 0; i <= l1; i++)
Zheng[i] = Lu[i];
}
if (l2 > l1) {
Yi = Hui;
Zheng = Hui;
for (int i = 0; i <= l2 - l1; i++)
Yi[i] = '0';
for (int i = l2 - l1, j = 0; j <= l1; j++, i++)
Yi[i] = Lu[j];
for (int i = 0; i <= l2; i++)
Zheng[i] = Hui[i];
}
int i, w = 0;
int e = max(l1, l2);
for (i = e; i >= 0; i--) {
int x = Zheng[i] - '0' + w, y = Yi[i] - '0';
if (x + y < 10) {
q.push(x + y);
w = 0;
}
else {
q.push((x + y) % 10);
w = 1;
if (i == 0)
q.push(1);
}
}
while (!q.empty()) {
int r = q.top(); q.pop();
printf("%d", r);
}
printf("\n");
}
return 0;
}
浙工大15新生赛 JLB A+B
最新推荐文章于 2021-01-02 20:52:47 发布