标签:else ret %s string scanf 转换 scan cst char s
#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;
}
标签:else ret %s string scanf 转换 scan cst char s
原文地址:https://www.cnblogs.com/ailinal/p/12387274.html