进制转换

#include <iostream>
using namespace std;
int main()
{
string s = "", table = "0123456789ABCDEF";
long long M = 0, N = 0;
cin >> M >> N;

if( M == 0)
{
s ="0";
}

while( M )
{
if( M < 0 )
{
M = -M;
cout << "-";
}
s = table[M % N] + s;
M /= N;
}
cout << s << endl;
return 0;
}

posted @ 2019-04-10 11:56  mc宇少  阅读(107)  评论(0编辑  收藏  举报