首页 > 代码库 > HDU-2031-进制转换
HDU-2031-进制转换
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=2031
进制转换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25604 Accepted Submission(s): 14260
#include<stdio.h>
int main()
{
int n,m,i,j,f,p;
char a[200];
while(~scanf("%d%d",&n,&m))
{
i=0;
p=0;
if(n<0)
{
p=-1;
n=-n;
}
while(n>0)
{
f=n%m;
if(f>=10)
a[i]=f-10+‘A‘;
else
a[i]=f+‘0‘;
i++;
n/=m;
}
if(p==-1)
printf("-");
for(j=i-1;j>=0;j--)
printf("%c",a[j]);
printf("\n");
}
return 0;
}
HDU-2031-进制转换