输入 :a n b
要求将a进制的n,以b进制输出
#include<stdio.h>
#include<string.h>
int main(){
int a ,b;
char str[100];
while(scanf("%d%s%d",&a,str,&b) != EOF){
int tmp =0;
int l = strlen(str);
int c =1;
for(int i = l-1;i> = 0; i–){
int x =0;
if(str[i]>=‘0’&&str[i]<=‘9’)
x=str[i] -‘0’;
else if (str[i]>=‘a’&&str[i]<=‘z’)
x=str[i]-‘a’ +10;
else
x=str[i] -‘A’ +10;
tmp = x * c;
c = c*a;
}
//上为a进制转成10进制
char ret[100];
int size = 0;
for(tmp !=0){
int x = tmp %b;
ans[size++] =x>10 ? ('A'+x-10) :x+'0' ;
tmp = tmp /b;
}
for(int i =siez -1;i>=0;i--)
printf("%d",ret[i]]);
printf("\n");
}
return 0;
}