基础练习 十六进制转八进制
#include<stdio.h>
#include<string.h>
int
b[1000005];//注意这里数组千万别开小了,开小了不过
char
s[1000005];
int
main()
{
int
n,i,k,j,temp,len;
char
c;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
len=strlen(s);
for(i=0;i<len;i++)
{
c=s[i];
if(c>=‘0‘&&c<=‘9‘)
temp=c-‘0‘;
else
temp=c-55;
j=3;k=4*i;
while(j>-1)
{
b[k+j]=temp%2;
j--;
temp=temp/2;
}
}
len=len*4-1;j=0;
while(len>=2)
{
temp=b[len]+(b[len-1])*2+b[len-2]*4;
s[j]=(char)(temp+‘0‘);
len=len-3;
j++;
}
i=0;temp=0;
while(i<=len)
{
temp=temp*2+b[i];
i++;
}
if(temp!=0)
{
s[j]=(char)(temp+‘0‘);
}
else
{
j--;
}
for(j;j>=0;j--)
{
printf("%c",s[j]);
}
printf("\n");
}
return
0;
}
原文:http://www.cnblogs.com/jianfengyun/p/3586650.html