找唯一数

来源:互联网 发布:手机端如何查看源码 编辑:程序博客网 时间:2024/06/06 03:45

Problem Description

在一个表长为n的顺序表中,除一个元素之外,其余的元素都出现了两次。请找出这个仅出现一次的元素。

 Input

有多组数据,每组第一行表示表长n(1<=n<=11111);第二行表示顺序表的各元素。

 Output

输出这个唯一数。

 Sample Input

52 2 1 3 172 1 1 3 -1 2 3

 Sample Output

3-1

 Hints

注意时间限制

 Author

hwt

 Recommend

zh


#include<iostream>
using namespace std;
int find(int * a,int N)  
{  
    int i;  
    int result=0;  
    for(i=0;i<N;i++)  
    {  
        result ^= a[i];  
    }  


  return result;
}  
int main(int argc, char* argv[])  
{  
    int n,a[11111],i;
while(cin>>n)
{
for(i=0;i<n;i++)
{
cin>>a[i];
}
   cout<<find(a,n)<<endl;  
}
    return 0;  


这^符号的妙用,在用一次可以找2个出现一样的数;



0 0