题解 | #进制转换#C++暴力遍历解法,注意特殊输入
进制转换
https://www.nowcoder.com/practice/ac61207721a34b74b06597fe6eb67c52
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int M=0;
int N=0;
cin>>M>>N;
string a;
int count=0;
if(M==0)
{
a+='0';
}
else
{
if(M<0)
{
count++;
M*=(-1);
}
while(M)
{
int m=M%N;
if(m>=10)
{
a+='A'+m-10;
}
else
{
a+=m+'0';
}
M/=N;
}
}
if(count)
{
a+='-';
}
reverse(a.begin(),a.end());
cout<<a;
return 0;
}


