Start: Mar, 06, 2018 09:46:00
计算机161 算法分析与设计 第一次实验课作业(吴银杰、张凯庆)
End: Mar, 10, 2018 10:00:00
Time elapsed:
Time remaining:

Problem_ID: E
Result: Accepted
Time: 7ms
Memory: 1092kB
Author: uzy
In contest: 1141

#include<stdio.h>
#include<stdlib.h>
int s[32];
char str[9];
int main(void){
	int t,i,j;
	scanf("%d",&t);
	for(i=0;i<t;i++){
		int m,k,a;
		getchar();
		gets(str);
		scanf("%d",&m);
		scanf("%d",&k);
	    for(j=0;j<8;j++){
	    	if(str[j]<='9'&&str[j]>='0')
	    	a=str[j]-'0';
	    	else
	    	a=str[j]-'0'-39;
	    	s[4*j+3]=a%2;
	    	s[4*j+2]=a/2%2;
	    	s[4*j+1]=a/2/2%2;
	    	s[4*j]=a/2/2/2%2;
		}
	    for(j=1;j<=m;j++){
	    	s[m-j]=k%2;
	    	k/=2;
		}
		for(j=0;j<8;j++){
			a=s[4*j+3]+2*s[4*j+2]+4*s[4*j+1]+8*s[4*j];
			if(a>=10)
			str[j]='0'+a+39;
			else
			str[j]='0'+a;
		}
		for(j=0;j<8;j++){
			printf("%c",str[j]);
		}
		printf("\n");
	}
	return 0;
}