题意:找出现次数不同于其他数的数。
超时了一次,后来知道了位运算。。。长见识了
0^0 =0
0^1=1
1^0=1
1^1=0
0^1^1 = 0
可以发现 任何数异或0还是他本身。
一个数异或另一个数偶数次还是他本身。
代码(位运算都600+ms):
#include <stdio.h>
#include <math.h>
int main()
{
int a, b, n;
while(scanf("%d", &n), n){
scanf("%d", &a);
n-=1;
while(n --){
scanf("%d", &b);
a = a^b;
printf("%d..", a);
}
printf("%d\n", a);
}
}
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2095