十六进制转八进制
#include<iostream>
using namespace std;
class chr
{
public:
char data;
chr *next;
static long int scanf(chr *start)
{
chr *h=start;
chr *pre=NULL;
char c;
long int len=0;
bool ok=false;
while(1)
{
c=getc(stdin);
if(!ok&&c=='\n')
continue;
if(c=='\n')
{
if(pre!=NULL)
pre->next=NULL;
delete h;
break;
}
if(!ok)
ok=true;
len++;
h->data=c;
pre=h;
h->next=new chr;
h=h->next;
h->next=NULL;
}
return len;
}
void release()
{
if(this->next==NULL)return;
this->next->release();
delete (this->next);
}
};
unsigned char hextodecimal(unsigned char y)
{
if(y>='A'&&y<='F')
return (y-'A'+10);
else if(y>='a'&&y<='f')
return (y-'a'+10);
else if(y>='0'&&y<='9')
return y-'0';
return 0;
}
void otc(chr **str,int strlens,char *out,int *len2,bool show=true)
{
if(strlens==0)
return;
int x=0;
for(int i=0;i<strlens;i++)
{
x<<=4;
unsigned char s=hextodecimal((unsigned char)(*str)->data);
*str=(*str)->next;
x|=s;
}
bool ok=false;
for(int i=0;i<4;i++)
{
unsigned char tt=((x>>(12-((i+1)*3)))&7);
if(!ok)
{
if(tt==0)
continue;
}
if(!ok&&tt!=0)
ok=true;
if(show)
printf("%d",tt);
else
{
out[*len2]=(char)(tt+'0');
*len2+=1;
}
}
}
int main()
{
chr *ts=new chr,*tmp;
int c;
cin>>c;
for(int i=0;i<c;i++)
{
long int len=chr::scanf(ts);
long int n=len/3;
int m=(int)(len%3);
int y=0;
tmp=ts;
otc(&tmp,m,NULL,NULL);
for(long int j=0;j<n;j++)
otc(&tmp,3,NULL,NULL);
ts->release();
printf("\n");
}
delete ts;
}