1022 D进制的A+B (20 分)
输入两个非负 10 进制整数 A 和 B (≤230−1),输出 A+B 的 D (1<D≤10)进制数。
输入格式:
输入在一行中依次给出 3 个整数 A、B 和 D。
输出格式:
输出 A+B 的 D 进制数。
输入样例:
123 456 8
输出样例:
1103
代码:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int a, b, d;
cin >> a >> b >> d;
int t = a + b;
if (t == 0)
{
cout << 0;
return 0;
}
int s[100];
int i = 0;
while (t != 0)
{
s[i++] = t % d;
t /= d;
}
for (int j = i - 1; j >= 0; j--)
{
cout << s[j];
}
return 0;
}