60pts求助
查看原帖
60pts求助
1265554
FanzhuoOVO楼主2024/7/30 10:59
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    int jin = 0;
    string a, b, c;
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    for(int i = 0; i < max(a.size(), b.size()); ++i)
    {
        int l = (a[i] - '0' + b[i] - '0') + jin;
        c += (l % 10) + '0';
        jin = l / 10;
        l %= 10;
    }
    if(jin == 1)
    {
        c += 1 + '0';
    }
    reverse(c.begin(), c.end());
    cout << c;
    return 0;
}

测试点数据

2024/7/30 10:59
加载中...