找出数组中非成对出现的数

来源:互联网 发布:jenkins 部署windows 编辑:程序博客网 时间:2024/05/01 04:03

有这样一个数组,除其中一个元素(如下面的99),其它的都是成对出现的,找出其中的非成对出现的数

102,2,102,2,11,144,88,23,23,144,11 

解决问题的代码如下

#include <iostream>
using namespace std;


int main()
{
    int a[11] = {102,32,99,32,45,102,45,67,67,100,100};
    int result = 0;
    for(int i=0; i<11; i++)
    {
        result ^= a[i];
    }
    cout<<result<<endl;
    return 0;
}

参考链接 http://blog.csdn.net/pathuang68/article/details/7567027