http://acm.hdu.edu.cn/showproblem.php?pid=2095
本题如果知道位运算那么将十分简单,其中需要用到^(异或符)。
真异或假的结果是真,假异或真的结果也是真,真异或真的结果是假,假异或假的结果是假。就是说两个值不相同,则异或结果为真。反之,为假。 不同为1,相同为0,如1001异或1010等于0011.(来自百度百科http://baike.baidu.com/view/674171.htm)
另有 a^b^c=a^(b^c)成立。
#include <stdio.h>
int main()
{
int result,n,t;
while(scanf("%d",&n)!=EOF&&n)
{
result=0;
for(int i=0;i<n;++i)
{
scanf("%d",&t);
result^=t;
}
printf("%d\n",result);
}
}