//找出数组中出现一次的两个数,其他数均出现两次
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
void Find(int arr[], int len)
{
int num1 = 0;
int num2 = 0;
int ret = 0;
int n = 0;
int i = 0;
int bit = 0;
for (i = 0; i < len; i++)
{
ret = ret ^ arr[i];
}
for (n = 0; n < 32; n++)
{
if ((ret >> n) & 1 == 1)
break;
}
for (i = 0; i < len; i++)
{
if ((arr[i] >> n) & 1 == 1)
num1 = num1 ^ arr[i];
else
num2 = num2 ^ arr[i];
}
printf(" num1=%d\n num2=%d\n", num1, num2);
}
int main()
{
int a[] = { 1,2,3,3,2,1,4,5 };
int len = sizeof(a) / sizeof(a[0]);
Find(a, len);
system("pause");
return 0;
}
//找出数组中出现一次的两个数,其他数均出现两次#define _CRT_SECURE_NO_WARNINGS 1#include #includevoid Find(int arr[], int len){ int num1 = 0; int num2 = 0; int ret = 0; int n = 0; int i = 0; int bit = 0; for (i ...