【算法代码】
#include <bits/stdc++.h>
using namespace std;
char get(int x) {
if(x<=9) return x+'0';
return x-10+'A';
}
string n2b(int n, int b) {
string ans;
while(n) {
ans+=get(n%b);
n/=b;
}
reverse(ans.begin(), ans.end());
return ans;
}
int main() {
int n,b;
cin>>n>>b;
cout<<n2b(n,b);
return 0;
}
/*
in:123 2
out:1111011
*/
【参考文献】
https://www.acwing.com/solution/content/29360/