#include<bits/stdc++.h>
using namespace std;
stack<int> num2;
stack<int> num;
stack<int> ans;
char x;
int main() {
while (1) {
x = getchar();
if (x > '9' || x < '0')break;
int a = x - '0';
num.push(a);
}
while (1) {
x = getchar();
if (x > '9' || x < '0')break;
int a = x - '0';
num2.push(a);
}
bool j = false;
while (!num.empty() && !num2.empty()) {
int f = num.top() + num2.top();
num.pop();
num2.pop();
if (j)f++, j = 0;
if (f > 9) {
f -= 10;
j = 1;
}
ans.push(f);
}
while (!num.empty()) {
int f = num.top();
if (j) {
f++;
j = 0;
}
if (f > 9) {
f -= 10;
j = 1;
}
ans.push(f);
num.pop();
}
while (!num2.empty()) {
int f = num2.top();
if (j) {
f++;
j = 0;
}
if (f > 9) {
f -= 10;
j = 1;
}
ans.push(f);
num2.pop();
}
if (j)cout << "1";
while (!ans.empty()) {
cout << ans.top();
ans.pop();
}
}
心血来潮写的高精度。
测试点2: 123 123
程序结果:246
我:???