#include<iostream>
#include<string>
using namespace std;
const int maxn = 10011;
int main()
{
int T;
cin>>T;
while(T--)
{
string a,b;
int c[maxn];
int i;
b = "";
cin>>a;
for(i=0; i<a.length(); i++)
switch(a[i])
{
case '0':
b += "0000";
break;
case '1':
b += "0001";
break;
case '2':
b += "0010";
break;
case '3':
b += "0011";
break;
case '4':
b += "0100";
break;
case '5':
b += "0101";
break;
case '6':
b += "0110";
break;
case '7':
b += "0111";
break;
case '8':
b += "1000";
break;
case '9':
b += "1001";
break;
case 'A':
b += "1010";
break;
case 'B':
b += "1011";
break;
case 'C':
b += "1100";
break;
case 'D':
b += "1101";
break;
case 'E':
b += "1110";
break;
case 'F':
b += "1111";
break;
}
int len1 = b.length();
int cnt;
cnt = 0;
if(len1 % 3 == 1)
{
b = "00" + b;
}
else if(len1 % 3 == 2)
{
b = "0" + b;
}
for(i=0;i<b.length();i++)
{
//cout<<b[i];
c[cnt++] = b[i] - '0';
}
int num;
num = 4*c[0] + 2*c[1] + 1*c[2];
if(num)
{
cout<<num;
}
for(int i=3; i<cnt; i+=3)
{
cout<<4*c[i] + 2*c[i+1] + 1*c[i+2];
}
cout<<endl;
}
return 0;
}
16进制转8进制(较为巧妙的做法)
最新推荐文章于 2024-05-04 02:33:28 发布