Result: Accepted
Time: 5ms
Memory: 1120kB
#include<stdio.h>
#include<string.h>
struct strings{
char str[5];
};
int main(void){
struct strings strs[8];
char a[9],b[33],c[33];
int i=0,n,m,T;
scanf("%d",&T);
while(T--){
scanf("%s",a);
for(int i=0;i<8;i++){
switch(a[i]){
case '0':strcpy(strs[i].str,"0000");break;
case '1':strcpy(strs[i].str,"0001");break;
case '2':strcpy(strs[i].str,"0010");break;
case '3':strcpy(strs[i].str,"0011");break;
case '4':strcpy(strs[i].str,"0100");break;
case '5':strcpy(strs[i].str,"0101");break;
case '6':strcpy(strs[i].str,"0110");break;
case '7':strcpy(strs[i].str,"0111");break;
case '8':strcpy(strs[i].str,"1000");break;
case '9':strcpy(strs[i].str,"1001");break;
case 'a':strcpy(strs[i].str,"1010");break;
case 'b':strcpy(strs[i].str,"1011");break;
case 'c':strcpy(strs[i].str,"1100");break;
case 'd':strcpy(strs[i].str,"1101");break;
case 'e':strcpy(strs[i].str,"1110");break;
case 'f':strcpy(strs[i].str,"1111");break;
}
if(i==0){
strcpy(b,strs[i].str);//字符串复制
}
if(i>0){
strcat(b,strs[i].str);//字符串连接
}
}
scanf("%d%d", &n,&m) ;
int x=0; //求物理块值的二进制
do {
c[x++]=m%2+'0';
m/=2;
} while(m!=0);
for(int r=0;r<n-x;r++){ //用0补位
b[r]='0';
}
int p=x-1;
for(int q=n-x;q<n;q++){ //进行替换
b[q]=c[p];
p--;
}
char dest[5]={""};
for(int h=0;h<8;h++){
strncpy(dest,b+4*h, 4); //每四个字符进行截取
if(strcmp(dest,"0000")==0){
printf("0");
}
if(strcmp(dest,"0001")==0){
printf("1");
}
if(strcmp(dest,"0010")==0){
printf("2");
}
if(strcmp(dest,"0011")==0){
printf("3");
}
if(strcmp(dest,"0100")==0){
printf("4");
}
if(strcmp(dest,"0101")==0){
printf("5");
}
if(strcmp(dest,"0110")==0){
printf("6");
}
if(strcmp(dest,"0111")==0){
printf("7");
}
if(strcmp(dest,"1000")==0){
printf("8");
}
if(strcmp(dest,"1001")==0){
printf("9");
}
if(strcmp(dest,"1010")==0){
printf("a");
}
if(strcmp(dest,"1011")==0){
printf("b");
}
if(strcmp(dest,"1100")==0){
printf("c");
}
if(strcmp(dest,"1101")==0){
printf("d");
}
if(strcmp(dest,"1110")==0){
printf("e");
}
if(strcmp(dest,"1111")==0){
printf("f");
}
}
printf("\n");
}
}