- 进制转换
- 2015-10-04 07:55:18 @
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char stack[100];
char num[50]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
int main()
{
freopen("in.cpp","r",stdin);
freopen("test.out","w",stdout);
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
memset(stack,0,sizeof(stack));
int cnt=1;
printf("%d=",a);
for(;a!=0;){
for(int i=0;i<-b;i++){
if((a-i)%(-b)==0){
stack[cnt++]=num[i];
a-=i;
break;
}
}
a/=b;
}
for(--cnt;cnt>0;cnt--)printf("%c",stack[cnt]);
printf("(base %d)\n",b);
}
}
2 条评论
-
TenderRun LV 10 @ 2015-10-04 15:19:16
其实还是AC了
-
2015-10-04 15:18:54@
好吧,我竟然忘记删除那两句话了
- 1