第一个数字是在数组里,第二个是个32bit uint
uncompleted, not mine code.
void add(vector<int> & a, uint b)
{
int remainder = 0;
int i;
for(i = a.size() - 1; i > -1 && b > 0; --i)
{
a[i] += remainder + b % 10;
b = b / 10;
if(a[i] >= 10)
{
a[i] -= 10;
remainder = 1;
}
else
{
remainder = 0;
}
}
if(i == -1)
{
while(b > 0)
{
uint x = b % 10 + remainder;
b = b / 10;
if(x >= 10)
{
x -= 10;
remainder = 1;
}
else
{
remainder = 0;
}
a.insert(a.begin(), x);
}
}
else if(remainder == 1)
{
for(int j = i; j > - 1; --j)
{
a[j] += remainder ;
if(a[j] >= 10)
{
a[j] -= 10;
remainder = 1;
}
else
{
break;
}
}
}
if(remainder == 1)
{
a.insert(a.begin(), 1);
}
}