题解 | #进制转换2# 任意进制转换,但数的大小有限
进制转换2
https://www.nowcoder.com/practice/ae4b3c4a968745618d65b866002bbd32
#include <iostream>
using namespace std;
int m, n;
string s;
int main() {
while(cin >> m >> n)
{
cin >> s;
long long num = 0;
char res[100];
int i = 0, k;
for(int i = 0; i < s.size(); i++)
if(s[i] >= 'A' && s[i] <= 'Z')
num = num * m + s[i] - 'A' + 10;
else
num = num * m + s[i] - '0';
//cout << num << endl;
while(num)
{
k = num % n;
num /= n;
if(k >= 10) res[i++] = k - 10 + 'a';
else res[i++] = k + '0';
}
for(int j = i - 1; j >= 0; j--)
cout << res[j];
cout << endl;
}
}

