问题标题: http://judge.codingtang.com/problem/1793/

0
0

3
0
0
梁锦程
梁锦程
高级光能
高级光能
string add(string x,string y)
{
    if(x.size()<y.size())
        swap(x,y);
    int lx=x.size(),ly=y.size(),f=0,a,b,s;
    while(lx>0)
    {
        a=x[lx-1]-'0';
        if(ly>0)
            b=y[ly-1]-'0';
        else b=0;
        s=a+b+f;
        if(s>=10)
        {
            x[lx-1]='0'+s%10;
            f=1;
        }
        else
        {
            x[lx-1]='0'+s;
            f=0;
        }
        lx--;
        ly--;
    }
    if(f==1)
        x="1"+x;
    return x;
}
我要回答