HDU 2095 find your present (2) 异或的经典运用

原题链接


异或的经典应用
异或运算法则  
1. a ^ b = b ^ a 
2. a ^ b ^ c = a ^ (b ^ c) = (a ^ b) ^ c; 
3. d = a ^ b ^ c 则 a = d ^ b ^ c. 

4. a ^ b ^ a = b    

附ac代码:

#include <stdio.h>

int main(){
	int t, a, b;
	while(scanf("%d", &t), t){
		a = 0;
		while(t-- && scanf("%d", &b))
			a ^= b;
		printf("%d\n", a);
	}
	return 0;
}



posted on 2013-12-16 13:00  长木Qiu  阅读(141)  评论(0编辑  收藏  举报