/* * 10进制转任意进制 * code by cc * 2009.10.03 */ #include <stdio.h> #include <string.h> void TenConvToOther(int ten, int jz, char s[]) { int i,j; char tmp; i = 0; while (ten > 0) { if (ten % jz <10) s[i] = '0' + ten % jz; else s[i] = 'A' + (ten % jz - 10); i++; ten /= jz; } s[i] = 0x00; for (j=0;j<i/2;j++) { tmp = s[j]; s[j] = s[i-j-1]; s[i-j-1] = tmp; } } int main() { int a,b; char s[100]; while (scanf("%d%d", &a, &b) != EOF) { if (a<0) { TenConvToOther(-a, b, s); printf("-%s/n", s); } else { TenConvToOther(a, b, s); printf("%s/n", s); } } return 0; }