http://acm.nit.net.cn/showproblem.jsp?pid=1016 注意数字范围,数字与字符 转换如3与‘3’。
a[2]={1,2,3]; printf("%s",a); 是123
#include <stdio.h>
#define BSIZE 36
void print_bin(int);
int main()
{
char bin[BSIZE] = {0};
char dexn[BSIZE] = {0};
unsigned long long dex;
int i;
int k;
while(scanf("%s",bin) == 1)
{
dex = 0;
k = 0;
for(i=0; i < BSIZE; i++)
{
if(bin[i] == 0) break;
dex = dex * 2 + (bin[i]-'0');
}
while(1)
{
if(dex < 10)
{
dexn[k++] = dex + '0';
break;
}
i = dex % 10;
dex = dex / 10;
dexn[k++] = '0'+i;
}
for(i=k-1; i >= 0; i--)
{
print_bin(dexn[i] - '0');
}
printf("\n");
}
return 0;
}
void print_bin(int digit)
{
switch(digit)
{
case 0: printf("0000");break;
case 1: printf("0001");break;
case 2: printf("0010");break;
case 3: printf("0011");break;
case 4: printf("0100");break;
case 5: printf("0101");break;
case 6: printf("0110");break;
case 7: printf("0111");break;
case 8: printf("1000");break;
case 9: printf("1001");break;
default : break;
}
}
1万+

被折叠的 条评论
为什么被折叠?



