0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 02:38:49 +00:00

B2143 进制转换

R52965724
This commit is contained in:
Baoshuo Ren 2021-07-13 09:10:24 +08:00 committed by Baoshuo Ren
parent 34b426f6b0
commit a566d63c0b
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,29 @@
#include <bits/stdc++.h>
using namespace std;
char itoc(int x) {
char r;
switch (x) {
case 10: r = 'A'; break;
case 11: r = 'B'; break;
case 12: r = 'C'; break;
case 13: r = 'D'; break;
case 14: r = 'E'; break;
case 15: r = 'F'; break;
default: r = x + '0'; break;
}
return r;
}
int main() {
string s, r;
int x, m;
cin >> x >> m;
while (x) {
r = itoc(x % m) + r;
x /= m;
}
cout << r << endl;
return 0;
}