C語言源碼: [cpp] #include<stdio.h> #include<string.h> int main() { int a,b,len,i,k,n; char s[100]; while(scanf("%d %s %d",&a,s,&b)!=EOF) { len=(int)strlen(s); n=0; k=1; for(i=len-1;i>=0;i--) { if(s[i]>='0'&&s[i]<='9') n+=(s[i]-'0')*k; else if(s[i]>='A'&&s[i]<='Z') n+=(s[i]-'A'+10)*k; else n+=(s[i]-'a'+10)*k; k=k*a; } len=0; if(n==0) s[len++]='0'; else while(n) { k=n%b; if(k>=10) s[len++]=k-10+'A'; else s[len++]=k+'0'; n=n/b; } for(i=len-1;i>=0;i--) printf("%c",s[i]); printf("\n"); } }