http://acm.hdu.edu.cn/showproblem.php?pid=2031
1 #include<stdio.h> 2 #include<math.h> 3 #include<string.h> 4 #include<stdlib.h> 5 #include<iostream> 6 using namespace std; 7 8 int main() 9 { 10 //freopen("in.txt","r",stdin); 11 int n,r; 12 int a[100]; 13 while(~scanf("%d%d",&n,&r)) 14 { 15 memset(a,0,sizeof(a)); 16 int fh=0; 17 if(n<0) 18 { 19 n=-n; 20 fh=1; 21 } 22 int t=0; 23 while(1) 24 { 25 a[t++]=n%r; 26 if(n/r==0) 27 break; 28 n=n/r; 29 } 30 if(fh==1) 31 printf("-"); 32 for(int i=t-1;i>=0;i--) 33 { 34 if(a[i]<10) 35 printf("%d",a[i]); 36 else 37 { 38 int q=a[i]+55; 39 printf("%c",q); 40 } 41 } 42 printf(" "); 43 } 44 return 0; 45 }