本文最后更新于 1163 天前,其中的信息可能已经有所发展或是发生改变。
代码语言:javascript复制#include<iostream>
#include <stdio.h>
#include<string>
using namespace std;
int main(){
int n,i,num;
cin>>n;
while(n--){
num=0;
string str1,str2="";
cin>>str1;
for(i=0;i<str1.length();i ){
switch(str1[i]){
case '0':str2 ="0000";break;
case '1':str2 ="0001";break;
case '2':str2 ="0010";break;
case '3':str2 ="0011";break;
case '4':str2 ="0100";break;
case '5':str2 ="0101";break;
case '6':str2 ="0110";break;
case '7':str2 ="0111";break;
case '8':str2 ="1000";break;
case '9':str2 ="1001";break;
case 'A':str2 ="1010";break;
case 'B':str2 ="1011";break;
case 'C':str2 ="1100";break;
case 'D':str2 ="1101";break;
case 'E':str2 ="1110";break;
case 'F':str2 ="1111";break;
}
}
if(str2.length()%3==1)
str2="00" str2;
if(str2.length()%3==2)
str2="0" str2;
for(i=0;i<str2.length();i =3){
num=(str2[i]-'0')*4 (str2[i 1]-'0')*2 (str2[i]-'0');
if(i==0&&num==0)
continue;
cout<<num;
}
cout<<endl;
}
return 0;
}
/*
int main(){
int n;
char c;
cin>>n;
c=getchar();
while(n--){
int len=0,s[100005],s1[100005],num,i,j,sum=0;
while((c=getchar())!='n'){
if(c=='A'){
num=10;
}
else if(c=='B'){
num=11;
}
else if(c=='C'){
num=12;
}
else if(c=='D'){
num=13;
}
else if(c=='E'){
num=14;
}
else if(c=='F'){
num=15;
}
else{
num=c-'0';
}
s[len]=num;
len ;
}
for(i=0;i<len;i ){
for(j=0;j<len-i-1;j ){
s[i]*=16;
}
sum =s[i];
}
//cout<<sum<<endl;
i=0;
while(sum) {
s1[i]=sum%8;
sum/=8;
i ;
}
for(i-=1;i>=0;i--){
cout<<s1[i];
}
cout<<endl;
}
return 0;
}
*/
Post Views: 215