http://acm.hdu.edu.cn/showproblem.php?pid=2031
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
char num[20]= {‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘};
char ans[maxn];
int main()
{
int n,d;
while(~scanf("%d%d",&n,&d))
{
int numm=0;
if(n<0)
{
n=n*-1;
printf("-");
}
do
{
ans[numm++]=num[n%d];
n/=d;
}
while(n!=0);
for(int i=numm-1;i>=0;i--)
{
if(i!=0)
printf("%c",ans[i]);
else
printf("%c\n",ans[i]);
}
}
return 0;
}
原文:https://www.cnblogs.com/zlrrrr/p/9321165.html