#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int m, n;
while (scanf("%d", &m) != EOF) {
scanf("%d", &n);
char s[1000];
scanf("%s", s);
int ns = strlen(s);
int a[1000];
for (int i = 0; i < ns; ++i) {
if (s[i] >= '0' && s[i] <= '9') a[i] = s[i] - '0';
else a[i] = s[i] - 'A' + 10;
}
int out[1000];
int no = 0;
for (int i = 0; i < ns;) {
int k = 0;
for (int j = i; j < ns; ++j) {
int temp = k * m + a[j];
k = temp % n;
a[j] = temp / n;
}
out[no++] = k;
while (a[i] == 0)i++;
}
for (int l = no - 1; l >= 0; --l) {
if (out[l]>=0 && out[l]<=9)
printf("%d", out[l]);
else
printf("%c",out[l]-10+'a');
}
printf("\n");
}
return 0;
}
问题 D: 进制转换
最新推荐文章于 2024-08-15 05:02:54 发布