题解 | #进制转换#
进制转换
http://www.nowcoder.com/practice/ac61207721a34b74b06597fe6eb67c52
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n,b;
string res, table = "0123456789ABCDEF";
cin >> n >> b;
if(n == 0) {
cout<<"0";
return 0;
}
int flag = 1;
if (n < 0) {
flag -= 2;
n *= -1;
}
while (n != 0) {
res += table[n%b];
n /= b;
}
if(flag == -1) res += "-";
reverse(res.begin(),res.end());
cout << res;
return 0;
}