|
楼主 |
发表于 2014-1-19 15:11:35
|
显示全部楼层
#include<stdio.h>
#include<string.h>
main()
{
char hex[10][10000],oxc[10][40001],olc[10][133334];
int n,i,j,o,temp,num=0;
scanf("%d",&n);
fflush(stdin);
for(i=0;i<n;i++)
{
scanf("%s",hex[i]);
strupr(hex[i]);
}
for(i=0;i<n;i++)
{
o=0;
for(j=0;j<strlen(hex[i]);j++)
{
switch(hex[i][j])
{
case '0':strcpy(&oxc[i][o],"0000");break;
case '1':strcpy(&oxc[i][o],"0001");break;
case '2':strcpy(&oxc[i][o],"0010");break;
case '3':strcpy(&oxc[i][o],"0011");break;
case '4':strcpy(&oxc[i][o],"0100");break;
case '5':strcpy(&oxc[i][o],"0101");break;
case '6':strcpy(&oxc[i][o],"0110");break;
case '7':strcpy(&oxc[i][o],"0111");break;
case '8':strcpy(&oxc[i][o],"1000");break;
case '9':strcpy(&oxc[i][o],"1001");break;
case 'A':strcpy(&oxc[i][o],"1010");break;
case 'B':strcpy(&oxc[i][o],"1011");break;
case 'C':strcpy(&oxc[i][o],"1100");break;
case 'D':strcpy(&oxc[i][o],"1101");break;
case 'E':strcpy(&oxc[i][o],"1110");break;
case 'F':strcpy(&oxc[i][o],"1111");break;
default :break;
}
o+=4;
}
}
for(i=0;i<n;i++)
{
if(strlen(oxc[i])%3)
o=1+strlen(oxc[i])/3;
else
o=strlen(oxc[i])/3;
olc[i][o]='\0';
for(j=strlen(oxc[i])-1;j>=0;j--)
{
temp=3;
while(temp>0){
if(oxc[i][j]=='1')
{
switch(temp)
{
case 3 :num+=1;break;
case 2 :num+=2;break;
case 1 :num+=4;break;
default:break;
}
}
--temp;
if(temp>0) --j;
}
olc[i][o-1]=num+'0';
num=0;
--o;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<strlen(olc[i]);j++)
{
if(olc[i][j]!='0')
printf("%c",olc[i][j]);
}
printf("\n");
}
return 0;
} |
-
|