为啥不可以大佬看看
查看原帖
为啥不可以大佬看看
871868
songshihao666888楼主2023/2/8 16:05
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int i; 
    string x, y,res; int dq, jw = 0;
    cin >> x >> y;
    reverse(x.begin(), x.end());
    reverse(y.begin(), y.end());
    for (i = 0; x[i] != '\0'; i++)
    {
        dq = (int)x[i] + (int)y[i] + jw;
        if (dq >= 10)
        {
            jw = dq / 10;
            dq %= 10;
        }
        else
        {
            jw = 0;
        }
        res[i] = (char)dq;
    }
    if (jw != 0)
    {
        res[i] = jw;
        i++;
    }
    reverse(res.begin(), res.end());
    cout << res;
    return 0;
}
2023/2/8 16:05
加载中...