#include<iostream>
using namespace std;
struct node {
int a[100005], len = 0;
node(int x = 0){
while(x > 0){
a[++ len] = x % 10;
x /= 10;
}
}
void print() {
for(int i = len; i >= 1; i--) {
cout << a[i];
}
}
};
node operator + (const node x, const node y){
node z(0);
z.len = max(x.len, y.len) + 2;
for(int i = 1;i <= z.len; i ++) {
z.a[i] += (x.a[i] + y.a[i]);
if(z.a[i] > 9) {
z.a[i + 1] += (z.a[i] / 10);
z.a[i] %= 10;
}
}
while(z.a[z.len] == 0) z.len--;
return z;
}
int main(){
node a(1), b(2);
a = a + b;
a.print();
a = a + a;
a.print();
return 0;
}
main 函数第一次输出 3,第一次加法没问题,第二次输出了8,就不对了。每次都是第二次加法都不对了。