题目来源:http://acm.hpu.edu.cn/vjudge/contest/view.action?cid=6#problem/G
代码:
#include
#include
#include
#include
int a[20000];
int fun(int m,int n)
{
int z=0;
while(m){
a[z++]=m%n;
m=m/n;
}
return z;
}
int main()
{
int m,n,k,i;
while(~scanf("%d%d",&m,&n))
{
k=fun(abs(m),n);
if(m<0)
printf("-");
for(i=k-1;i>=0;i--)
{
if(a[i]>9)
printf("%c",a[i]-10+'A');
else
printf("%d",a[i]);
}
printf("\n");
}
return 0;
}