题意:输入两个int范围内的非负十进制整数 还有一个进制D 要求输出D进制的A+B的和
思路:普通的进制转换,除进制取余数然后倒过来reverse之类的或者直接倒过来输出
代码难度不是很大 烦人的是测试点3的A+B=0的特殊情况(也是我一直欠缺的)所以特意把非负在这里标了一下
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main()
{
int a, b, c, d;
cin >> a >> b >> d;
c = a + b;
int i = 0;
vector<int>q;
while (c)
{
int ls = c % d;
q.push_back(ls);
c /= d;
}
reverse(q.begin(), q.end());
if (q.size() != 0)
for (int i = 0; i < q.size(); i++)
cout << q[i];
else
cout << 0;
cout << endl;
system("pause");
return 0;
}