用异或找独特数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1563

当然比较直接的想法使用一个哈希表。但更好的方法是用异或!!

#include<stdio.h>
int  main(){
    int n,m,s;
    while(scanf("%d",&n),n) {
     s=0;
     while(n--) {
         scanf("%d",&m);
         s^=m;
     }
     printf("%d\n",s);
    }
    return 0;
}

 

posted @ 2014-12-29 07:59  zmiao  阅读(185)  评论(0)    收藏  举报