#include<iostream>
#include<string>
using namespace std;
int ctoi(const char& ch)
{
return ch - '0';
}
int getBase(const char& ch)
{
return ch == '0' ? 10 : ctoi(ch);
}
int main()
{
string a, b, _Base, result;
cin >> _Base >> a >> b;
while (a.size() < _Base.size()) a = '0' + a;
while (b.size() < _Base.size()) b = '0' + b;
int up = 0, sum, base;
for (int index = a.size() - 1; index >= 0; --index)
{
sum = ctoi(a[index]) + ctoi(b[index]) + up;
base = getBase(_Base[index]);
up = sum / base;
result.push_back((sum % base) + '0');
}
if (up > 0)
result.push_back(up + '0');
while (result.back() == '0' && result.size() > 1)
result.pop_back();
cout << string(result.rbegin(), result.rend()) << endl;
system("pause");
return 0;
}
PAT 乙级 1074 宇宙无敌加法器 (20分)
最新推荐文章于 2022-12-05 19:34:34 发布