#include "iostream"
#include "string"
using namespace std;
int main()
{
int i, j, lans, linput, temp, jin;
string ans, input;
cin >> ans;
while (cin >> input && input != "0")
{
lans = ans.length();
linput = input.length();
jin = 0;
if (lans >= linput)
{
for (i = lans - 1, j = linput - 1; j >= 0; i--, j--)
{
temp = ans[i] - 48 + input[j] - 48 + jin;
ans[i] = temp % 10 + 48;
jin = temp / 10;
}
for (; i >= 0; i--)
{
if (jin == 0)
break;
temp = ans[i] - 48 + jin;
ans[i] = temp % 10 + 48;
jin = temp / 10;
}
if (jin == 1)
ans = '1' + ans;
}
else
{
for (i = lans - 1, j = linput - 1; i >= 0; i--, j--)
{
temp = ans[i] - 48 + input[j] - 48 + jin;
input[i] = temp % 10 + 48;
jin = temp / 10;
}
for (; j >= 0; j--)
{
if (jin == 0)
break;
temp = input[j] - 48 + jin;
input[j] = temp % 10 + 48;
jin = temp / 10;
}
if (jin == 1)
ans = input + '1';
else
ans = input;
}
}
cout << ans << endl;
system("pause");
}
poj 1503 Integer Inquiry
最新推荐文章于 2020-05-20 20:01:54 发布