#include <iostream>
using namespace std;
int k=3;
int find_single(int* a, int n)
{
int i, j;
int single = 0;
int temp[32];
for(i=0; i<32; i++)
temp[i] = 0;
for(i=0; i<n; i++)
for(j=0; j<32; j++)
temp[j] += ((a[i]>>j)&1);
for(i=0; i<32; i++)
single |= ((temp[i]%k)<<i);
return single;
}
int main()
{
int a[] = {10,2,2,2,3,3,3,4,4,4,8,8,8};
cout<<find_single(a, sizeof(a)/sizeof(a[0]))<<endl;
return 0;
}
找出只出现一次的数,其他数都出现了k次
最新推荐文章于 2021-07-10 10:26:01 发布