高精度加法

#include <bits/stdc++.h>
#define MAX 1000
using namespace std;


int main() {
    char s1[MAX], s2[MAX];
    cin >> s1 >> s2;
    int len1 = strlen(s1), len2 = strlen(s2), i, tmp;
    int data1[MAX], data2[MAX], res[MAX];

    memset(data1, 0, sizeof(data1));
    memset(data2, 0, sizeof(data2));
    memset(res, 0, sizeof(res));

    for (i = 0; i < len1; i++)
        data1[i] = s1[len1 - 1 - i] - '0';
    for (i = 0; i < len2; i++)
        data2[i] = s2[len2 - 1 - i] - '0';

    int len3 = max(len1, len2) + 1;
    for (i = 0; i < len3 - 1; i++) {
        tmp = res[i] + data1[i] + data2[i];
        res[i + 1] += tmp / 10;
        res[i] = tmp % 10;
    }
    for (i = len3; res[i] == 0; i--);
    for (; i >= 0; i--)
        cout << res[i];
}