题目
样例
代码
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int len = 510;
int main() {
string x, y;
while (cin>>x>>y)
{
int result[len] = { 0 };
int lenx = x.length();
int leny = y.length();
int pos = len - 1;
int i, j;
int posx = lenx - 1;
int posy = leny - 1;
while (posx>=0 && posy>=0)
result[pos--] = (x[posx--] - '0') + (y[posy--] - '0');
if(lenx>leny)
while (posx>=0)
result[pos--] = x[posx--] - '0';
else
while (posy >= 0)
result[pos--] = y[posy--] - '0';
for (i = len - 1; i >= 0; i--) {
if (result[i] >= 10) {
result[i - 1] += result[i] / 10;
result[i] = result[i] % 10;
}
}
int start = 0;
for (i = 0; i < len; i++) {
if (result[i] != 0) break;
start++;
}
for (i = start; i <= len-1; i++)
cout << result[i];
cout << endl;
}
return 0;
}