Start: Jan, 08, 2018 19:10:00
2017年秋季学期程序设计基础(C语言)期末考试
End: Jan, 08, 2018 21:40:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 6ms
Memory: 1092kB
In contest: 1139

#include<stdio.h>
#include<math.h>

int main(void){
	long long a;
	int b, c, d, g, x, i, num, flag;
	int e[32],f[32],h[32];
	scanf("%d",&b);
	while(b--){
		flag = 0;
		num = 31;
		scanf("%llx",&a);
		scanf("%d%d",&c,&d);
		while(num >= 0){
			e[num--] = a % 2;
			a /= 2;
		}
		c--;
		x = c;
		while(x >= 0){
			f[x--] = d % 2;
			d /= 2;
		}
		x = c;
		for(i = 0;i <= x;i++){
			if(f[i]){
				h[i] = 1;
			}
			else{
				h[i] = 0;
			}
		}
		for(i = x + 1;i < 32;i++){
			if(e[i]){
				h[i] = 1;
			}
			else{
				h[i] = 0;
			}
		}
		for(i = 0;i <= 28;i += 4){
			if(!flag){
				if(h[i] * 8 + h[i + 1] * 4 + h[i + 2] * 2 + h[i + 3]){
					flag++;
					printf("%x",h[i] * 8 + h[i + 1] * 4 + h[i + 2] * 2 + h[i + 3]);
				}
				else{
					printf("0");
				}
			}
			else{
				printf("%x",h[i] * 8 + h[i + 1] * 4 + h[i + 2] * 2 + h[i + 3]);
			}
		}
		printf("\n");
	}
	return 0;
}