1022-D进制的A+B
leenickzh Lv4

输入两个非负10进制整数AB(<=−1),输出A+BD(1<D<=10)进制数.

输入格式

输入在一行中依次给出3个整数ABD.

输出格式

输出A+BD进制数.

输入样例

1
123 456 8

输出样例

1
1103

分析

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
int A, B, D;
cin >> A >> B >> D;
int sum = A + B;
string res;
while (sum != 0)
{
res.append(to_string(sum % D));
sum /= D;
}
reverse(res.begin(), res.end());
if (res.empty())
{
cout << "0" << endl;
}
else
{
cout << res << endl;
}
return 0;
}
  • Post title:1022-D进制的A+B
  • Post author:leenickzh
  • Create time:2021-05-31 22:14:13
  • Post link:https://nickk.cn/2021/05/31/1022-D进制的A+B/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments